Repository navigation
Description
Current behavior 🐛
A packaged WinAppSDK head on .NET 10 with trimming on (PublishTrimmed=true, TrimMode full or partial) crashes about 3 seconds after launch. WER reports 0xc000027b in Microsoft.UI.Xaml.dll with 0x802B000A (E_XAMLPARSEFAILED). A first-chance exception log shows why:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
at DailyPlants.DailyPlants_XamlTypeInfo.XamlTypeInfoProvider.InitTypeTables()
at DailyPlants.DailyPlants_XamlTypeInfo.XamlTypeInfoProvider.LookupTypeIndexByName(String typeName)
The untrimmed package runs fine. The Uno and WinUI publish profiles (Properties/PublishProfiles/win-*.pubxml) turn trimming on for Release, so a Release "package and publish" produces a package that crashes.
Root cause: in Uno.WinUI's buildTransitive/uno.winui.winappsdk.targets, _UnoRemoveReferences removes the NuGet-resolved Uno.WinUI references. It then re-adds $(PkgUno_WinUI)/lib/net9.0-windows10.0.19041.0/*.dll (a hardcoded TFM) to ReferencePath and ReferenceCopyLocalPaths, even when the app is .NET 10 and NuGet resolved lib/net10.0-windows10.0.19041.0/. In publish:
RuntimeCopyLocalItemsand_ManagedRuntimeAssemblyhold the net10 path (the NuGet asset).ResolveOverlappingItemGroupConflictskeeps the net9 path inResolvedFileToPublish._ComputeManagedAssemblyToLinkjoins by path, finds no match, and passes the net9Uno.UI.Toolkit.dllthrough untouched. It's never linked or ReadyToRun-compiled; the packaged file is byte-identical to the net9 NuGet file.- ILLink removes the facades nothing else references (
System.Runtime,System.Runtime.Loader,System.Threading,System.Numerics.Vectors).Uno.UI.Toolkit.dllstill references them, so the generated XAML type info fails to load its types.
(Both the net9 and net10 Uno.UI.Toolkit.dll reference System.Runtime 9.0.0.0. That's harmless once the assembly actually goes through the linker.)
The same bypass also means that a blank app which never uses Uno.UI.Toolkit still ships it untrimmed (~246 KB with its .pri and Generic.xbf), which a plain WinUI app doesn't.
On master (7.0) the path is lib/net10.0-windows10.0.19041.0 and the assembly is Uno.UI.Extras.dll. The path now matches the NuGet asset, so it probably links correctly (not verified), but it's still hardcoded to one TFM and will break the same way once a second Windows TFM ships. _UnoIncludeUIToolkit hardcodes the same path for the .pri and the Uno.UI.Toolkit/** assets.
Expected behavior 🎯
A trimmed .NET 10 WinAppSDK app starts, and Uno.UI.Toolkit.dll goes through the linker like any other package assembly.
How to reproduce it (as minimally and precisely as possible) 🔬
- Take an Uno app on Uno.Sdk 6.x (WinAppSDK head,
net10.0-windows10.0.xxxxx) that uses something fromUno.UI.Toolkitin XAML (e.g.xmlns:toolkit="using:Uno.UI.Toolkit"withtoolkit:VisibleBoundsPadding.PaddingMask), so the XAML type info touches its types. msbuild -restore /p:TargetFramework=net10.0-windows10.0.26100 /p:Configuration=Release /p:Platform=x64 /p:GenerateAppxPackageOnBuild=true(the default pubxml turns onPublishTrimmed).- Install and launch the
.msix. It crashes at startup. The packagedUno.UI.Toolkit.dllis the net9 file, andSystem.Runtime.dllisn't in the package.
Workaround 🛠️
Save NuGet's own items before Uno swaps them and put them back afterwards. Verified: the trimmed app starts, every page renders, and Uno.UI.Toolkit.dll is linked (243 KB → 135 KB):
<Target Name="SaveNuGetUnoWinUIReferences" BeforeTargets="_UnoRemoveReferences" Condition="'$(IsWinAppSdk)' == 'true' and '$(PkgUno_WinUI)' != ''">
<ItemGroup>
<_NuGetUnoWinUIReference Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)' == 'Uno.WinUI'" />
<_NuGetUnoWinUICopyLocal Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'Uno.WinUI'" />
</ItemGroup>
</Target>
<Target Name="RestoreNuGetUnoWinUIReferences" AfterTargets="_UnoRemoveReferences" Condition="'$(IsWinAppSdk)' == 'true' and '$(PkgUno_WinUI)' != ''">
<ItemGroup>
<_UnoNet9Assembly Include="$(PkgUno_WinUI)/lib/net9.0-windows10.0.19041.0/*.dll" />
<ReferencePath Remove="@(_UnoNet9Assembly)" />
<ReferenceCopyLocalPaths Remove="@(_UnoNet9Assembly)" />
<ReferencePath Include="@(_NuGetUnoWinUIReference)" />
<ReferenceCopyLocalPaths Include="@(_NuGetUnoWinUICopyLocal)" />
</ItemGroup>
</Target>(Re-adding @(RuntimeCopyLocalItems) instead doesn't work: the item gets CopyLocal=true, is counted twice, and ReadyToRun fails with MSB4094.)
Suggested fix: stop replacing items NuGet already resolved correctly, or derive the path from the resolved asset / $(TargetFramework) instead of hardcoding a TFM.
Renderer 🎨
- Skia
- Native
Affected platforms 📱💻🖥️
Windows App SDK, Build tasks
Uno.Sdk version (and other relevant versions) 📦
Uno.Sdk 6.6.0-dev.196 (Uno.WinUI 6.6.0-dev.1303). The same hardcoded net9 path is in Uno.WinUI 6.7.65 and 6.8.0-dev.130. Microsoft.WindowsAppSDK 1.7.250909003, .NET SDK 10.0.401, net10.0-windows10.0.26100.
IDE version 🧑💻
Command-line MSBuild (Visual Studio 18 Insiders build tools); VS "Package and Publish" uses the same pubxml.
Anything else we need to know? 💬
Trimming is the biggest size lever on Windows: in the app where this was found, the x64 package goes from 252 MB to 130 MB installed.
Activity
fix(winappsdk): Keep NuGet's Windows assets so trimming links them
fix: Keep the trimmed Windows package from crashing at startup
fix: Keep the trimmed Windows package from crashing at startup
fix: Keep the trimmed Windows package from crashing at startup
fix: Keep the trimmed Windows package from crashing at startup
fix: Keep the trimmed Windows package from crashing at startup
fix: Keep the trimmed Windows package from crashing at startup
fix: Keep the trimmed Windows package from crashing at startup
fix: Keep the trimmed Windows package from crashing at startup
fix: Keep the trimmed Windows package from crashing at startup
fix: Keep the trimmed Windows package from crashing at startup