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

[BUG] NativeAOT Trim warnings #2447

Open
2 tasks done
trampster opened this issue Jan 16, 2025 · 3 comments
Open
2 tasks done

[BUG] NativeAOT Trim warnings #2447

trampster opened this issue Jan 16, 2025 · 3 comments
Labels
bug Something isn't working unverified

Comments

@trampster
Copy link

trampster commented Jan 16, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

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

  1. Create a MAUI project that targets iOS with .net 9 MAUI
  2. Add reference to CommCommunityToolkit.Maui <PackageReference Include="CommunityToolkit.Maui" Version="10.0.0" />
  3. Use the InvertedBoolConverter in xaml
  4. Add bits required to turn on NativeAOT:
<IsAotCompatible>true</IsAotCompatible>
<PublishAot Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">true</PublishAot>
  1. Build using dotnet publish -f net9.0-ios -r ios-arm64
    -> trim warnings from description

Link to public reproduction project repository

MauiCommunityToolkitTrimIssue

Environment

- .NET MAUI CommunityToolkit: 10.0.0
- OS: iOS
- .NET MAUI: 9.0.21

Anything else?

No response

@trampster trampster added bug Something isn't working unverified labels Jan 16, 2025
Copy link
Contributor

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 bug section of our Contributing.md that 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
Copy link
Author

trampster commented Jan 16, 2025

I have added a link to a reproduction sample. https://github.com/trampster/MauiCommunityToolkitTrimIssue

@trampster
Copy link
Author

trampster commented Jan 16, 2025

As a work arround we have created our own InvertBoolConverter that does not produce trim warnings:


[AcceptEmptyServiceProvider]
public class InvertBoolConverter : IValueConverter
{
   public object Convert(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
   {
      return !((bool)(value ?? false));
   }

   public object ConvertBack(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
   {
      return value ?? false;
   }
}

Feel free to use this until the Maui CommunityToolkit is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unverified
Projects
None yet
Development

No branches or pull requests

2 participants