Skip to content

TodoApp.Uno: trim analysis warnings (IL2026/IL2104/IL2121) on browserwasm/ios/maccatalyst heads #534

Description

@adrianhall

Summary

Now that #525/#524 (PR #533) fix the EventTriggerBehavior/UXAML0001 build failure and let TodoApp.Uno actually build on the browserwasm, ios, and maccatalyst heads for the first time in CI, those heads surface IL trim-analysis warnings that were previously masked by the earlier build failure:

warning IL2026: Using member 'System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' ... [Database/TodoItem.cs]
warning IL2026: Using member 'Microsoft.EntityFrameworkCore.DbContext.DbContext(DbContextOptions)' which has 'RequiresUnreferencedCodeAttribute' ... [Database/AppDbContext.cs]
warning IL2026: Using member 'Uno.Extensions.Hosting.IApplicationBuilder.Build()' ... [App.xaml.cs]
warning IL2026: Using member 'Uno.Extensions.ApplicationBuilderExtensions.NavigateAsync<TShell>(...)' ... [App.xaml.cs]
warning IL2026: Using member 'Uno.Extensions.HostBuilderExtensions.UseNavigation(...)' ... [App.xaml.cs]
warning IL2026: Using member 'Microsoft.Xaml.Interactivity.{EventTriggerBehavior,DataTriggerBehavior,CallMethodAction,ChangePropertyAction}...' - Uno.UI.SourceGenerators-generated BindableMetadata.g.cs
warning IL2104: Assembly '<various>' produced trim warnings (maccatalyst only - roll-up notices for System.Private.Xml, System.Private.CoreLib, CommunityToolkit.Datasync.Client, CommunityToolkit.WinUI.*, EF Core assemblies, Microsoft.Spatial)
warning IL2121: Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2026'/'IL2111' in Uno.UI.SourceGenerators-generated TodoListPage/Shell code (maccatalyst only)

CI run: https://github.com/CommunityToolkit/Datasync/actions/runs/29093946725 (todoapp-uno / browserwasm, todoapp-uno / ios-maccatalyst jobs)

Root cause

This is the exact same class of finding as #521 (fixed for the Avalonia/MAUI samples via PR #531): net10.0-ios/net10.0-maccatalyst/net10.0-browserwasm mark the project trimmable by default, so the IL trim analyzer runs during dotnet build - not just dotnet publish -p:PublishTrimmed=true. None of the flagged APIs are bugs in the sample:

  • EF Core's DbContext(DbContextOptions) constructor is explicitly documented as not fully trim-compatible (https://aka.ms/efcore-docs-trimming).
  • System.Text.Json.JsonSerializer.Serialize<TValue> without a JsonTypeInfo/JsonSerializerContext is inherently reflection-based by design.
  • The Uno.Extensions.Hosting/Navigation APIs and Microsoft.Xaml.Interactivity behaviors are Uno's own framework surface, flagged by Uno's own source-generated code (BindableMetadata.g.cs), not sample code.
  • IL2121 is emitted against Uno.UI.SourceGenerators' own generated file (TodoListPage_....cs), not sample code, and only appears on maccatalyst.

As established in #521/#531: this repo's CI only ever runs dotnet build for these samples, never dotnet publish -p:PublishTrimmed=true, so trim analysis here is purely diagnostic noise with no functional consequence.

Suggested fix

Mirror PR #531's approach: add <SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings> to samples/todoapp/TodoApp.Uno/TodoApp.Uno/TodoApp.Uno.csproj, scoped to the affected TFMs (net10.0-browserwasm, net10.0-ios, net10.0-maccatalyst) via the same GetTargetPlatformIdentifier-conditional pattern used in TodoApp.MAUI.csproj. Confirm whether android/desktop/windows need the same treatment (they didn't surface these warnings in the CI run linked above, but that may depend on the exact SDK/workload combination).

Related

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions