maui icon indicating copy to clipboard operation
maui copied to clipboard

[Trimming] Fix several trimming warnings

Open simonrozsival opened this issue 1 year ago • 1 comments

Description of Change

This PR fixes the following 10 trimming warnings:

src/Controls/src/Core/ResourceDictionary.cs(50): Trim analysis warning IL2067: Microsoft.Maui.Controls.ResourceDictionary.<>c.<SetAndLoadSource>b__8_0(Type): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter 'key' of method 'Microsoft.Maui.Controls.ResourceDictionary.<>c.<SetAndLoadSource>b__8_0(Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
src/Controls/src/Core/BindableProperty.cs(89): Trim analysis warning IL2067: Microsoft.Maui.Controls.BindableProperty.BindableProperty(String,Type,Type,Object,BindingMode,BindableProperty.ValidateValueDelegate,BindableProperty.BindingPropertyChangedDelegate,BindableProperty.BindingPropertyChangingDelegate,BindableProperty.CoerceValueDelegate,BindableProperty.BindablePropertyBindingChanging,Boolean,BindableProperty.CreateDefaultValueDelegate): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter '#1' of method 'Microsoft.Maui.Controls.BindableProperty.BindableProperty(String,Type,Type,Object,BindingMode,BindableProperty.ValidateValueDelegate,BindableProperty.BindingPropertyChangedDelegate,BindableProperty.BindingPropertyChangingDelegate,BindableProperty.CoerceValueDelegate,BindableProperty.BindablePropertyBindingChanging,Boolean,BindableProperty.CreateDefaultValueDelegate)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
src/Core/src/HotReload/HotReloadHelper.cs(64): Trim analysis warning IL2067: Microsoft.Maui.HotReload.MauiHotReloadHelper.GetReplacedView(IHotReloadableView): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter '#ILLink.Shared.TypeSystemProxy.ParameterIndex' of method 'System.Collections.Generic.Dictionary`2<String,Type>.TryGetValue(String,Type&)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
src/Core/src/HotReload/HotReloadHelper.cs(64): Trim analysis warning IL2067: Microsoft.Maui.HotReload.MauiHotReloadHelper.GetReplacedView(IHotReloadableView): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Activator.CreateInstance(Type,Object[])'. The parameter '#ILLink.Shared.TypeSystemProxy.ParameterIndex' of method 'System.Collections.Generic.Dictionary`2<String,Type>.TryGetValue(String,Type&)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
src/Controls/src/Core/Routing.cs(122): Trim analysis warning IL2111: Microsoft.Maui.Controls.Routing..cctor(): Method 'Microsoft.Maui.Controls.Routing.RegisterRoute(String,Type)' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method.
src/Controls/src/Core/DependencyService.cs(95): Trim analysis warning IL2073: Microsoft.Maui.Controls.DependencyService.FindImplementor(Type): 'Microsoft.Maui.Controls.DependencyService.FindImplementor(Type)' method return value does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' requirements. The return value of method 'System.Linq.Enumerable.FirstOrDefault<Type>(IEnumerable`1<Type>,Func`2<Type,Boolean>)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
src/Controls/src/Core/Xaml/TypeConversionExtensions.cs(74): Trim analysis warning IL2072: Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.<>c__DisplayClass2_0.<ConvertTo>b__0(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.GetTypeConverterType(IEnumerable`1<CustomAttributeData>)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
src/Controls/src/Core/Xaml/TypeConversionExtensions.cs(91): Trim analysis warning IL2072: Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.<>c__DisplayClass2_0.<ConvertTo>b__0(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.GetTypeConverterType(IEnumerable`1<CustomAttributeData>)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
src/Controls/src/Core/Xaml/TypeConversionExtensions.cs(112): Trim analysis warning IL2057: Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.GetTypeConverterType(IEnumerable`1<CustomAttributeData>): Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
src/Controls/src/Core/Xaml/TypeConversionExtensions.cs(56): Trim analysis warning IL2072: Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.<>c__DisplayClass1_0.<ConvertTo>b__0(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.GetTypeConverterType(IEnumerable`1<CustomAttributeData>)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Notes:

  • I can't see any other way of fixing the warning in Routing.cs other than the suppression.
  • The MetadataUpdater.IsSupported API is not available in netstandard. I chose to keep the current behavior (IsSupported == true).

/cc @vitek-karas

Issues Fixed

Fixes several warnings mentioned in #19397

simonrozsival avatar Dec 13 '23 16:12 simonrozsival

/cc @jonathanpeppers

simonrozsival avatar Jan 09 '24 17:01 simonrozsival