Repository navigation
Closed
Labels
Description
Is there an existing issue for this?
- I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
The following Trim warnings are geneated when trying to use the CommunityToolkit with NativeAOT in .net 9 Maui on iOS:
ILC : Trim analysis warning IL2092: CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Microsoft.Maui.Controls.IValueConverter.Convert(Object,Type,Object,CultureInfo): 'DynamicallyAccessedMemberTypes' in 'DynamicallyAccessedMembersAttribute' on the parameter '' of method 'CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Microsoft.Maui.Controls.IValueConverter.Convert(Object,Type,Object,CultureInfo)' don't match overridden parameter '' of method 'Microsoft.Maui.Controls.IValueConverter.Convert(Object,Type,Object,CultureInfo)'. All overridden members must have the same 'DynamicallyAccessedMembersAttribute' usage.
ILC : Trim analysis warning IL2092: CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Microsoft.Maui.Controls.IValueConverter.ConvertBack(Object,Type,Object,CultureInfo): 'DynamicallyAccessedMemberTypes' in 'DynamicallyAccessedMembersAttribute' on the parameter '' of method 'CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Microsoft.Maui.Controls.IValueConverter.ConvertBack(Object,Type,Object,CultureInfo)' don't match overridden parameter '' of method 'Microsoft.Maui.Controls.IValueConverter.ConvertBack(Object,Type,Object,CultureInfo)'. All overridden members must have the same 'DynamicallyAccessedMembersAttribute' usage.
ILC : Trim analysis warning IL2092: CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Microsoft.Maui.Controls.IValueConverter.Convert(Object,Type,Object,CultureInfo): 'DynamicallyAccessedMemberTypes' in 'DynamicallyAccessedMembersAttribute' on the parameter '' of method 'CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Microsoft.Maui.Controls.IValueConverter.Convert(Object,Type,Object,CultureInfo)' don't match overridden parameter '' of method 'Microsoft.Maui.Controls.IValueConverter.Convert(Object,Type,Object,CultureInfo)'. All overridden members must have the same 'DynamicallyAccessedMembersAttribute' usage.
ILC : Trim analysis warning IL2092: CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Microsoft.Maui.Controls.IValueConverter.ConvertBack(Object,Type,Object,CultureInfo): 'DynamicallyAccessedMemberTypes' in 'DynamicallyAccessedMembersAttribute' on the parameter '' of method 'CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Microsoft.Maui.Controls.IValueConverter.ConvertBack(Object,Type,Object,CultureInfo)' don't match overridden parameter '' of method 'Microsoft.Maui.Controls.IValueConverter.ConvertBack(Object,Type,Object,CultureInfo)'. All overridden members must have the same 'DynamicallyAccessedMembersAttribute' usage.
/_/src/CommunityToolkit.Maui/Extensions/ValueConverterExtension.shared.cs(31): Trim analysis warning IL2062: CommunityToolkit.Maui.Extensions.ValueConverterExtension.IsValidTargetType<TTarget>(Type&,Boolean): Value passed to parameter 'type' of method 'System.Activator.CreateInstance(Type)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements.
Expected Behavior
No Trim warnings
Reproduction Sample
https://github.com/trampster/MauiCommunityToolkitTrimIssue
Steps To Reproduce
- Create a MAUI project that targets iOS with .net 9 MAUI
- Add reference to CommCommunityToolkit.Maui
<PackageReference Include="CommunityToolkit.Maui" Version="10.0.0" /> - Use the InvertedBoolConverter in xaml
- Add bits required to turn on NativeAOT:
<IsAotCompatible>true</IsAotCompatible>
<PublishAot Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">true</PublishAot>
- Build using
dotnet publish -f net9.0-ios -r ios-arm64
-> trim warnings from description
Link to public reproduction project repository
Environment
- .NET MAUI CommunityToolkit: 10.0.0
- OS: iOS
- .NET MAUI: 9.0.21Anything else?
No response
Activity
dotnet-policy-service commentedon Jan 16, 2025
Hi @trampster! We have added the needs reproduction label to this issue, which indicates that we are unable to take further action until you provide a reproduction sample that we can use to reproduce + fix your bug. In accordance with the
Reporting a bugsection of ourContributing.mdthat you confirmed reading before you submitted this Issue, we ask that every Issue author provide a link to an open-source repository containing the reproduction sample app. This issue will be closed automatically in 5 days if we do not receive a reproduction sample from you. Please feel free to re-open this Issue once you have provided a reproduction sample.trampster commentedon Jan 16, 2025
I have added a link to a reproduction sample. https://github.com/trampster/MauiCommunityToolkitTrimIssue
trampster commentedon Jan 16, 2025
As a work arround we have created our own InvertBoolConverter that does not produce trim warnings:
Feel free to use this until the Maui CommunityToolkit is fixed.
jfversluis commentedon Jan 20, 2025
@simonrozsival is there any way to prevent this other than to use
#pragma disable?simonrozsival commentedon Jan 20, 2025
@jfversluis The reason the warnings are shown is that
the
ICommunityToolkitValueConverteradds[DynamicallyAccessedMembers]attribute to parameters that don't have it in the baseIValueConverterdefinition:Maui/src/CommunityToolkit.Maui/Converters/ICommunityToolkitValueConverter.shared.cs
Lines 55 to 62 in e66f78e
The
#pragma warning disable IL2092silences the roslyn analyzer, but when the NativeAOT compiler (ILC) later compiles the IL, it won't see that #pragma. Instead, it is necessary to use[UnconditionalSuppressMessage]to completely silence those warnings. Something like this should do the trick:jfversluis commentedon Jan 20, 2025
@trampster would you be able to test the resulting NuGets from this PR build to verify if that fixes this scenario for you in your project?