Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Trimming] Fix several trimming warnings #19402

Merged

Conversation

simonrozsival
Copy link
Member

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 simonrozsival added the area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) label Dec 13, 2023
simonrozsival and others added 3 commits December 14, 2023 11:17
Co-authored-by: Vitek Karas <10670590+vitek-karas@users.noreply.github.com>
@simonrozsival simonrozsival marked this pull request as ready for review December 15, 2023 13:57
@simonrozsival simonrozsival requested a review from a team as a code owner December 15, 2023 13:57
@samhouts samhouts added the stale Indicates a stale issue/pr and will be closed soon label Jan 8, 2024
@simonrozsival
Copy link
Member Author

/cc @jonathanpeppers

@hartez hartez removed their request for review January 10, 2024 20:21
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good now, and doesn't seem like it will change the behavior of anything. Seems ok for main.

Can someone in @dotnet/dotnet-maui-reviewers review? Thanks!

@mattleibow mattleibow merged commit a36ceae into dotnet:main Jan 16, 2024
47 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) fixed-in-8.0.7 fixed-in-9.0.100-preview.1.9973 stale Indicates a stale issue/pr and will be closed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants