Skip to content

fix: suppress IL2026/IL2104 trim analysis warnings on mobile TodoApp samples#531

Merged
adrianhall merged 4 commits into
CommunityToolkit:mainfrom
adrianhall:issues/521
Jul 10, 2026
Merged

fix: suppress IL2026/IL2104 trim analysis warnings on mobile TodoApp samples#531
adrianhall merged 4 commits into
CommunityToolkit:mainfrom
adrianhall:issues/521

Conversation

@adrianhall

Copy link
Copy Markdown
Collaborator

Summary

Fixes #521.

net10.0-ios (and mobile TFMs generally) enable the IL trim analyzer during dotnet build — not just dotnet publish — because these SDKs mark projects trimmable by default. This surfaced IL2026/IL2104 warnings on the TodoApp.Avalonia.iOS build (surfaced by the mobile CI added in #511 / PR #519), pointing at documented, trim-unsafe framework APIs:

  • Avalonia's BindingPlugins.DataValidators (inherently reflection-based, by design)
  • EF Core's DbContext(DbContextOptions) constructor (explicitly documented as not fully trim-compatible: https://aka.ms/efcore-docs-trimming)

Neither is a bug in the sample code — both are idiomatic, documented usage of their respective frameworks, exactly as taught in docs/samples/todoapp/avalonia.md.

Why suppress rather than fix the code

This repo's CI only ever runs dotnet build for these samples (see build-samples-todoapp-avalonia.yml / build-samples-todoapp-maui.yml) — never dotnet publish -p:PublishTrimmed=true. So today, trim analysis on these projects is purely diagnostic noise: no actual IL trimming/linking ever happens, and no app is shipped from this pipeline. Avoiding the flagged APIs would mean fighting Avalonia/EF Core's own recommended patterns for the sake of a warning with no functional consequence in a build-only pipeline, and would make the samples worse as teaching examples.

Changes

Added <SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>:

  • samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.iOS/TodoApp.Avalonia.iOS.csproj — the confirmed, reported case.
  • samples/todoapp/TodoApp.Avalonia/TodoApp.Avalonia.Android/TodoApp.Avalonia.Android.csproj — same shared code path (App.axaml.cs / AppDbContext.cs) is compiled under this TFM too; added precautionarily even though Android didn't surface the warning in the CI run that filed the issue.
  • samples/todoapp/TodoApp.MAUI/TodoApp.MAUI.csproj — scoped to the net10.0-ios TFM only (via the GetTargetPlatformIdentifier conditional pattern already used elsewhere in this file), since the Android/Windows heads weren't confirmed to have the warning.

Each edit includes a comment explaining the root cause and linking back to #521.

Bonus: this also avoids the analyzer's build-time cost, not just its warning output

Per the actual Microsoft.NET.ILLink.targets shipped in the SDK:

<PropertyGroup Condition="'$(SuppressTrimAnalysisWarnings)' == 'true'">
  <_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --notrimwarn</_ExtraTrimmerArgs>
  <EnableTrimAnalyzer Condition="'$(EnableTrimAnalyzer)' == ''">false</EnableTrimAnalyzer>
</PropertyGroup>

Setting SuppressTrimAnalysisWarnings=true also sets EnableTrimAnalyzer=false (since we don't set EnableTrimAnalyzer explicitly ourselves), which disables the analyzer pass itself rather than merely hiding its output. Separately, the actual ILLink linking task (the potentially slow part) is only ever wired into the publish pipeline, not build — so it was never running here in the first place.

Testing

  • dotnet build on the shared TodoApp.Avalonia.csproj and TodoApp.Avalonia.Desktop.csproj — succeeded (1 pre-existing, unrelated nullable warning).
  • dotnet restore / dotnet build --configuration Release on Datasync.Toolkit.sln — succeeded, 0 warnings/0 errors. (This solution doesn't include the edited sample projects, confirming no impact on the core library.)
  • dotnet test Datasync.Toolkit.sln --configuration ReleaseCommunityToolkit.Datasync.Client.Test: 1432/1432 passed. CommunityToolkit.Datasync.Server.Test had pre-existing, environment-only failures (no local Docker daemon; that suite depends on TestContainers) — confirmed identical failure count with the changes stashed out, so unrelated to this PR.
  • Could not locally build the actual net10.0-ios / MAUI-iOS heads to visually confirm the warnings disappear (no Xcode/iOS workload available locally) — deferred to this repo's CI, which pins the exact Xcode/workload versions that originally surfaced the warnings.

Related

ahall added 4 commits July 10, 2026 12:00
…samples

net10.0-ios (and mobile TFMs generally) enable the IL trim analyzer during
'dotnet build', not just 'dotnet publish', because these SDKs are marked
trimmable by default. This surfaced IL2026/IL2104 warnings on
TodoApp.Avalonia.iOS pointing at documented, trim-unsafe framework APIs
(Avalonia's BindingPlugins.DataValidators, EF Core's
DbContext(DbContextOptions) ctor) - not bugs in the sample code.

The CI pipelines for these samples only ever run 'dotnet build', never
'dotnet publish -p:PublishTrimmed=true', so no actual IL trimming/linking
occurs; the analyzer is pure diagnostic noise here.

Add <SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings> to:
- TodoApp.Avalonia.iOS.csproj (the confirmed, reported case)
- TodoApp.Avalonia.Android.csproj (same shared code path, precautionary)
- TodoApp.MAUI.csproj, scoped to the net10.0-ios TFM only

Per Microsoft.NET.ILLink.targets, this property also sets
EnableTrimAnalyzer=false, which disables the analyzer pass itself (not
just its warning output), avoiding any analyzer-related build-time cost
in addition to the noise.

Fixes CommunityToolkit#521
Watching PR CommunityToolkit#531's CI run revealed a distinct, more expensive problem than
the trim-analyzer warnings fixed in the prior commit: net10.0-ios Release
builds run the actual ILLink trimmer (not just the analyzer) even for a
plain 'dotnet build' against a simulator RID. 'Optimizing assemblies for
size' / 'IL stripping assemblies' dominates ~90% of the build time,
stretching the todoapp-avalonia/ios and todoapp-maui/ios jobs to 15+
minutes each, while the equivalent Android jobs for the same samples
complete in ~3.5 minutes total.

Since these CI jobs only ever run 'dotnet build' as a compile sanity
check - never 'dotnet publish' - there is no benefit to actually linking
here. Pass -p:PublishTrimmed=false on the dotnet build command line for
the two affected 'ios' jobs only:
- build-samples-todoapp-avalonia.yml
- build-samples-todoapp-maui.yml

Deliberately a CI-only override (not a .csproj change), so a developer
following the tutorial who runs a real 'dotnet publish' still gets the
platform's normal trimming default and app size.

Related to CommunityToolkit#521
…builds

The prior commit's -p:PublishTrimmed=false broke both iOS jobs immediately
(confirmed via CI run 29089733157): the iOS SDK hard-rejects it -

  error: iOS projects must build with PublishTrimmed=true. Current value:
  false. Set 'MtouchLink=None' instead to disable trimming for all
  assemblies. [Xamarin.Shared.Sdk.targets(304,3)]

Switch to the SDK-blessed -p:MtouchLink=None, which keeps the mandatory
PublishTrimmed=true while skipping the actual link/strip work that was
dominating build time.
Per https://blog.verslu.is/maui/exclude-assemblies-from-trimming/, Debug
configuration avoids .NET's IL trimming/AOT machinery entirely, which is a
simpler and more broadly effective fix than the prior MtouchLink=None
command-line workaround (removed here - no longer needed).

These CI workflows are build-only compile sanity checks - none of them
publish or ship an app - so there is no reason to pay for Release-only
optimizations (trimming, AOT) anywhere in this matrix. Switch
DOTNET_CONFIGURATION from Release to Debug across all build-samples-*.yml
workflows for consistency, not just the two mobile ones that were
observed to be slow.

build-library.yml and build-template.yml are intentionally left at
Release, since those build the actual shipped library and dotnet
template, not a sample.

Related to CommunityToolkit#521
@adrianhall adrianhall merged commit ebd5ad2 into CommunityToolkit:main Jul 10, 2026
15 checks passed
@adrianhall adrianhall deleted the issues/521 branch July 10, 2026 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IL2026/IL2104 trim analysis warnings on TodoApp.Avalonia.iOS build

1 participant