dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.23k stars 4.72k forks source link

Incorrect message for IL2026 for trim-sunsafe types in XAML type info metadata table #109272

Open Sergio0694 opened 3 days ago

Sergio0694 commented 3 days ago

Description

I noticed some IL2026 messages are wrong, for types in the XAML compiler generated metadata table:

"[...]\x64\net9.0-windows10.0.26100.0\XamlTypeInfo.g.cs(632,75): warning IL2026: Using member '[...]_XamlTypeInfo.XamlTypeInfoProvider.InitTypeTables()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code.This behavior is not trim-safe."

That message can't be right, as InitTypeTables has no trim annotations on it. In fact, this is what you see:

Image

That is, the diagnostic location seems right. Microsoft.Xaml.Interactions.Core.EventTriggerBehavior has [RequiresUnreferencedCode], and it's used as a type argument here. But somehow the type name in the message is the name of the parent InitTypeTables() method where this assignment is.

Reproduction Steps

Same as #109270. Can't share repro steps here (since the code is not open source). I can however share:

Expected behavior

The message should correctly indicate the problematic type.

Actual behavior

See screenshot above.

dotnet-policy-service[bot] commented 3 days ago

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas See info in area-owners.md if you want to be subscribed.