Skip to content

fix(winappsdk): Keep NuGet's Windows assets so trimming links them - #25860

Merged
ramezgerges merged 1 commit into
unoplatform:masterfrom
ramezgerges:dev/rara/winappsdk-nuget-windows-assets
Nov 2, 2026
Merged

ramezgerges merged 1 commit into
unoplatform:masterfrom
ramezgerges:dev/rara/winappsdk-nuget-windows-assets

Conversation

@ramezgerges

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24577

PR Type:

🐞 Bugfix

What changed? 🚀

A trimmed WinAppSDK app can crash at startup (0xC000027B in Microsoft.UI.Xaml.dll, FileNotFoundException: System.Runtime) because Uno.UI.Extras.dll skips the linker.

Cause. _UnoRemoveReferences (uno.winui.winappsdk.targets) removed the Uno.WinUI references NuGet resolved and re-added $(PkgUno_WinUI)/lib/net10.0-windows10.0.19041.0/*.dll, whatever the app's TFM. The package ships lib/net10.0-windows… and lib/net11.0-windows…, so for a net11 app:

  • NuGet resolves the net11 Uno.UI.Extras.dll, and the runtime/linker items keep that path;
  • the reference/copy-local items now point at the net10 file, which wins the publish conflict resolution;
  • the linker joins by path, finds no match and passes the net10 file through untouched;
  • it removes the facades only that untouched assembly references (System.Runtime, System.Threading), and the XAML type info fails to load Uno.UI.Extras types at startup.

The issue reports the same on 6.x, where the hardcoded folder is net9 and every .NET 10 app is affected; on master it's .NET 11 apps.

Fix.

  • When NuGet already resolved Uno.WinUI's Windows assets for the app's TFM, they're kept as they are, so they go through trimming and ReadyToRun like any package assembly.
  • The swap still runs when NuGet picked the cross-platform lib/net1x.0 (a TFM below the package's Windows SDK version), from the folder matching the app's .NET version (GetTargetFrameworkVersion) instead of a hardcoded one.
  • _UnoIncludeUIExtras takes the .pri and Uno.UI.Extras/** assets from that same folder.

Validation (runtime): a minimal net11.0-windows10.0.26100.0 WinAppSDK app on Uno.WinUI 7.0.0-dev.2509 using ex:CommandBarExtensions.Subtitle (Uno.UI.Extras) in XAML, self-contained unpackaged publish (with EnableMsixTooling), with these targets applied by overriding the two package targets:

Variant Published Uno.UI.Extras.dll Result
Untrimmed net10 package file starts
TrimMode=full, current targets net10 package file, untouched; System.Runtime.dll/System.Threading.dll trimmed crash 0xC000027B, FileNotFoundException: System.Runtime, Version=10.0.0.0
TrimMode=full, this PR linked (69 KB vs 284 KB) starts

Not covered: the fallback branch end to end. With a net11.0-windows10.0.17763.0 TFM NuGet does resolve lib/net11.0, but the app fails to compile with CS0433 (DispatcherQueue defined in two assemblies) both with and without this change, so that branch's behavior is unchanged but not exercised. Validated unpackaged, not as MSIX (same linker inputs).

6.x (servicing/6.8, release/stable/6.7) hardcode net9 and would need a backport.

PR Checklist ✅

🤖 Generated with Claude Code

_UnoRemoveReferences replaced the Uno.WinUI references NuGet resolved
with lib/net10.0-windows10.0.19041.0, whatever the app's TFM. In a net11
app the published Uno.UI.Extras.dll no longer matched the item the
linker works from, so it shipped untrimmed while the linker removed the
facades it references, and the app crashed at startup (fixes unoplatform#24577).

The Windows assets NuGet resolved are now kept. The swap only runs when
NuGet picked the cross-platform assets, from the folder matching the
app's .NET version, which the Extras .pri and assets use too.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added the area/build Categorizes an issue or PR as relevant to build infrastructure label Oct 31, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@mergify

mergify Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@ramezgerges
ramezgerges merged commit 1c877d1 into unoplatform:master Nov 2, 2026
52 checks passed
@ramezgerges
ramezgerges deleted the dev/rara/winappsdk-nuget-windows-assets branch November 2, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build Categorizes an issue or PR as relevant to build infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trimmed .NET 10 WinAppSDK app crashes at startup: Uno.WinUI swaps in its net9 Uno.UI.Toolkit.dll, which skips the linker

3 participants