dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.97k stars 1.72k forks source link

Trim warnings when publishing `dotnet new maui` #24062

Closed jkurdek closed 2 weeks ago

jkurdek commented 1 month ago

Context: https://github.com/dotnet/maui/pull/22282 Context: https://github.com/dotnet/maui/issues/18658

User should be able to specify TrimMode = full and publish and dotnet new maui template without trim warnings. I created a dotnet new maui template and tried to trim it. I observed that I can see some trim warnings relegated to hot reload, which disappear with consecutive publish attempts.

Reproduce steps:

  1. ../maui/dotnet-local.sh new maui -n sampleApp
  2. Add following property group:
    <PropertyGroup Condition="'$(Configuration)' == 'Release'">
        <TrimMode>full</TrimMode>
        <MauiStrictXamlCompilation>true</MauiStrictXamlCompilation>
        <MauiXamlRuntimeParsingSupport>false</MauiXamlRuntimeParsingSupport>
        <MauiShellSearchResultsRendererDisplayMemberNameSupported>false</MauiShellSearchResultsRendererDisplayMemberNameSupported>
        <MauiQueryPropertyAttributeSupport>false</MauiQueryPropertyAttributeSupport>
        <MauiImplicitCastOperatorsUsageViaReflectionSupport>false</MauiImplicitCastOperatorsUsageViaReflectionSupport>
    </PropertyGroup>
  1. ../../maui/dotnet-local.sh publish -f net9.0-maccatalyst -r maccatalyst-arm64 -p:TrimmerSingleWarn=false

This results in the following output:

    /Users/jeremi/Repos/maui/src/Core/src/HotReload/HotReloadHelper.cs(72,5): 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 'value' of method 'System.Collections.Generic.Dictionary<TKey,TValue>.TryGetValue(Dictionary<TKey,TValue>.TKey, Dictionary<TKey,TValue>.TValue&)' 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.
    /Users/jeremi/Repos/maui/src/Core/src/HotReload/HotReloadHelper.cs(72,5): 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 'value' of method 'System.Collections.Generic.Dictionary<TKey,TValue>.TryGetValue(Dictionary<TKey,TValue>.TKey, Dictionary<TKey,TValue>.TValue&)' 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.

Binlog inspection shows that both warnings are issued by the ILLink task

github-actions[bot] commented 1 month ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.