Repository navigation
fix(trimming): Suppress IL2026 on bindable activators - #26630
Conversation
|
This pull request is merged. |
|
If these annotations are suppressed, when will users see that IL2026 warning when using the behavior? |
Good question. From XAML, they don't today, and they didn't before this PR either. The XAML generator emits The warnings removed here came from The real fix is for the XAML generator to report |
a2ac6a9 to
1802642
Compare
The bindable metadata generator emits a CreateInstance activator for every createable bindable type in referenced assemblies, used or not. When the type or its parameterless constructor carries [RequiresUnreferencedCode] (e.g. CallMethodAction and EventTriggerBehavior in Uno.Microsoft.Xaml.Behaviors.Interactivity), the trim analyzer reported an IL2026 on BindableMetadata.g.cs that the app could not act on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1802642 to
b57955a
Compare
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
GitHub Issue: closes unoplatform/add-private#62
PR Type:
🐞 Bugfix
What changed? 🚀
Before: the bindable metadata generator emits a
CreateInstance()activator (new T()) for every createable bindable type in referenced assemblies, whether the app uses it or not. When the type or its parameterless constructor is marked[RequiresUnreferencedCode], the trim analyzer reports IL2026 inBindableMetadata.g.cs, and the app can't do anything about it. For example, referencingUno.Microsoft.Xaml.Behaviors.Interactivity.WinUI4.0.1 gives four of these warnings:CallMethodAction,ChangePropertyAction,DataTriggerBehaviorandEventTriggerBehavior.After: when the type or its activator constructor carries
[RequiresUnreferencedCode], the activator gets[UnconditionalSuppressMessage("Trimming", "IL2026", ...)]. This matches what the generated code already does elsewhere:Build()in the same file and the XAML generator'sInitializeComponentalready blanket-suppress IL2026.IsCreateableis replaced byGetActivatorConstructor, which both the activator emission and the attribute check use.Validation
When_Constructor_Requires_Unreferenced_Code_Then_Activator_Suppresses_IL2026covers three cases:[RequiresUnreferencedCode]on the type, on the constructor only, and a trim-safe type that must not get the suppression. It fails without the fix.When_RequiresUnreferencedCode_Is_Polyfilled_Then_Activator_Suppresses_IL2026covers a polyfilled copy of the attribute (suppressed) and a same-named attribute in another namespace (not suppressed). The fullUno.UI.SourceGenerators.Testssuite passes (639 passed, 7 skipped, 0 failed).net10.0-desktop,EnableTrimAnalyzer=true): 4 IL2026 with the published generator, 0 with this branch's generator. The suppression lands on exactly those four activators.EventTriggerBehavior/CallMethodActionin XAML produces no IL2026 at the use site, before or after the fix, becauseInitializeComponentis already suppressed.PublishTrimmed=true,win-x64, self-contained) of the same repro: ILLink reports the same 4 IL2026 inBindableMetadata.g.cswith the published generator, and none with this branch's generator. The other trim warnings are the same in both runs (2 IL2104, forUno.UI.Runtime.MacOSandUno.UI.Runtime.Win32). To get ILLink to finish, the WebView2Aot/DirectNAot references were kept out of ILLink. Otherwise it hangs on theICoreWebView2_*interface chain, independently of this change (ILLink takes exponential time on deep interface hierarchies dotnet/runtime#136766, Trimmed Skia Desktop publish hangs #24618).PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code