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

Spurious trimmer warning is not suppressed #1269

Closed
jkoritzinsky opened this issue Nov 11, 2022 · 0 comments · Fixed by #1272
Closed

Spurious trimmer warning is not suppressed #1269

jkoritzinsky opened this issue Nov 11, 2022 · 0 comments · Fixed by #1272
Assignees
Labels
bug Something isn't working trimming
Milestone

Comments

@jkoritzinsky
Copy link
Member

jkoritzinsky commented Nov 11, 2022

Describe the bug

@Sergio0694 and I found that the following trim warnings are emitted by a default WinUI 3 project (built with "trimmer-safe" CsWinRT projections):

1>ILLink : Trim analysis warning IL2026: WinRT.Projections..cctor(): Using member 'System.MulticastDelegate.MulticastDelegate(Object, String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The target method might be removed.
1>ILLink : Trim analysis warning IL2026: WinRT.Projections..cctor(): Using member 'System.Delegate.Delegate(Object, String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The target method might be removed.
1>ILLink : Trim analysis warning IL2026: WinRT.Projections..cctor(): Using member 'System.Delegate.CreateDelegate(Type, Object, String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The target method might be removed.
1>ILLink : Trim analysis warning IL2026: WinRT.Projections..cctor(): Using member 'System.Delegate.CreateDelegate(Type, Object, String, Boolean, Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The target method might be removed.
1>ILLink : Trim analysis warning IL2026: WinRT.Projections..cctor(): Using member 'System.Delegate.CreateDelegate(Type, Object, String, Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The target method might be removed.

These warnings are emitted because Projections.RegisterCustomAbiTypeMappingNoLock has DynamicallyAccessedMembers(PublicMethods) on the type parameter, and a delegate type typeof(EventHandler<>) is passed in. As a result, the trimmer warns about these methods with RequiresUnreferencedCodeAttribute since it can't be sure you don't access these methods through reflection. These warnings aren't emitted by the trimmer analyzer due to dotnet/linker#3111.

These warnings should be suppressed because these methods are never invoked via reflection based on the usage.

To Reproduce

  1. Create a default WinUI 3 project
  2. Set <PublishTrimmed>true</PublishTrimmed>
  3. Publish the project.

Expected behavior

No trimmer warnings from WinRT.Runtime.dll

Version Info

VS2022.4

Additional context

@Sergio0694 has a repro.

@jkoritzinsky jkoritzinsky added the bug Something isn't working label Nov 11, 2022
@manodasanW manodasanW self-assigned this Nov 12, 2022
@manodasanW manodasanW added this to the Release 2.0.1 milestone Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working trimming
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants