You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trimmed publish of a blank .NET 10 Uno Skia Desktop app without WebView hangs at Optimizing assemblies for size. This process might take a while. with Uno.Sdk 6.7.18 and later.
Expected behavior 🎯
WebView2Aot should not be included when WebView is unused, and trimmed publish should complete promptly.
How to reproduce it (as minimally and precisely as possible) 🔬
A blank app is generated from the Uno template:
dotnet new install Uno.Templates
dotnet new unoapp -n UnoPublishRepro -o UnoPublishRepro -preset blank -tfm net10.0 -skip
In the generated global.json, Uno.Sdk is set to 6.7.18. On Linux, the following command is run from the generated directory:
WebView2Aot was added to the Win32 runtime for .NET 10 by Uno PR #23621, without a WebView feature condition. DirectNAot is pulled in transitively. The slowdown is resolved when these assemblies are removed from linker inputs.
Root cause found: this is an ILLink bug (exponential time on deep interface hierarchies), triggered by the WebView2Aot interop that the Win32 host always ships. Two fixes are open:
Uno.UI.Runtime.Win32 references WebView2Aot (and through it DirectNAot, 21 MB) unconditionally, so every desktop head ships them, on every OS.
WebView2Aot is generated with [GeneratedComInterface]. Its versioned interfaces form a 29-deep chain: ICoreWebView2_29 : ICoreWebView2_28, …, ICoreWebView2.
Interface metadata lists every inherited interface, so ILLink reaches the same interface through exponentially many paths. Three walks follow all of them:
A stuck publish sits in TypeMapInfo.FindAndAddDefaultInterfaceImplementations, recursing deeply. It's still there on current packages: Uno.Sdk 7.0.0-dev.113 with ILLink 10.0.10, still running after 15 min at 4.2 GB.
Isolating it
DirectN.dll linked alone: 38 s whether all of it is rooted or just its public surface, so DirectN is not the problem.
WebView2.dll rooted: still running after 5 minutes.
Marking DirectN as trimmable: still hangs.
Uno-less repro: a plain console app with a chain of empty interfaces (I1, I2 : I1, … I26 : I25, ILeaf : I26) and dotnet publish -p:PublishTrimmed=true. It takes 13 s at depth 22 and 92 s at depth 26, and keeps growing about 7× every 4 levels. Exact steps are in ILLink takes exponential time on deep interface hierarchies dotnet/runtime#136766.
The output is byte-identical to stock ILLink wherever stock ILLink completes: 95 assemblies of a trimmed desktop app, and the depth-16 generated-COM library.
On dotnet/runtime main, Mono.Linker.Tests passes (1307 passed, 0 failed), plus a new DeepInterfaceHierarchy regression test. That test passes in about 0.5 s; without the fix, the suite hits a 3-minute hang timeout.
The docs already require the WebView Uno Feature for WebView on -desktop. Heads without it now drop the three packages' assets after package resolution; UnoIncludeWebView2Aot=true keeps them.
The Win32 host registers its WebView implementation lazily, so a non-WebView app runs fine without them.
The blank-app trimmed publish goes from hanging to 18 s, the app starts, and no new trim warnings appear.
Until the ILLink fix ships in a .NET servicing release, a desktop app that uses WebView and trims its publish stays blocked. Its only workaround is to disable trimming.
@ramezgerges#25862 doesn't seem to cover trimmed publish. A desktop head without WebView still hangs at "Optimizing assemblies for size" on Uno.Sdk 7.0.22 (uno.winui 7.0.65), which includes #25862.
Repro: a desktop head with UnoFeatures = Skia only, no Microsoft.Web.WebView2 anywhere in the graph:
ILLink ran for 2h+ and grew to ~20 GB before I stopped it. Stack samples show it in MarkStep → TypeMapInfo.MapType → FindAndAddDefaultInterfaceImplementations, the walk from dotnet/runtime#136766.
Why:_UnoRemoveUnusedWebView2Aot removes WebView2Aot/DirectNAot from RuntimeCopyLocalItems/NativeCopyLocalItems. Their compile assets stay in ReferencePath, because Uno.UI.Runtime.Win32 compiles against them. The ILLink task passes every ReferencePath item it isn't linking as a reference:
--action skip only means the assembly isn't rewritten. ILLink still loads it, marks the WebView2 types that Uno.UI.Runtime.Win32 touches, and builds their type maps, so the 29-deep ICoreWebView2_* chain is walked anyway.
Confirmed: the same ILLink invocation without the WebView2, DirectN and DirectN.Extensions references finishes in 9 s. The whole trimmed publish, with them removed from ReferencePath right before ILLink, takes ~13 s. There were no new warnings: only the two IL2104 summaries for Uno.UI.Runtime.MacOS and Uno.UI.Runtime.Win32, which are there either way. I haven't run the trimmed app.
The workaround I used, which may also be the shape of a fix in Uno.SingleProject.Desktop.targets:
<TargetName="HideWebView2FromILLink"BeforeTargets="_RunILLink">
<ItemGroup>
<_HiddenReferenceInclude="@(ReferencePath)"Condition="'%(Filename)' == 'WebView2' or '%(Filename)' == 'DirectN' or '%(Filename)' == 'DirectN.Extensions'" />
<ReferencePathRemove="@(_HiddenReference)" />
</ItemGroup>
</Target>
In the SDK, it would reuse _UnoUnusedWebView2Packages (matching %(NuGetPackageId)) instead of hardcoding file names, so DirectN stays when something else owns it. _RunILLink is an SDK-internal target name, so hooking PrepareForILLink may be sturdier.
#25862 was timed on its first revision, which also removed the WebView2Aot/DirectN compile assets, so ILLink never saw them (18 s). A later revision kept the compile assets so heads that use DirectN still compile, and I didn't re-time the trimmed publish after that change. The merged version hangs exactly as you describe. On the same machine today, the first revision publishes in 16 s and the merged one is still in ILLink after 10 minutes, so it isn't the Uno version or the .NET SDK.
#26696 takes the shape you suggested: after PrepareForILLink, it removes the packages already listed in _UnoUnusedWebView2Packages from ReferencePath, matched by NuGetPackageId, and puts them back after ILLink. Tested by repacking Uno.Sdk 7.0.22 with only that change, on a fresh unoapp desktop head with UnoFeatures = Skia:
Trimmed publish: 18 s; no WebView2/DirectN shipped; the trimmed app starts and renders.
Head that uses DirectN itself: only WebView2 is hidden; DirectN ships and its code runs in the trimmed app.
Warnings: with TrimmerSingleWarn=false, only the existing IL2050 (UI Automation) and IL2026 (macOS WebView) warnings, none about the hidden assemblies.
NativeAOT: unaffected either way; ILC isn't given these assemblies.
Apps that do use a WebView still need the ILLink fix (dotnet/runtime#136766) for a trimmed publish.
Activity
ramezgerges commentedon Oct 31, 2026
Root cause found: this is an ILLink bug (exponential time on deep interface hierarchies), triggered by the WebView2Aot interop that the Win32 host always ships. Two fixes are open:
webviewfeature. That covers the case in this issue, a blank app with no WebView.What happens
Uno.UI.Runtime.Win32referencesWebView2Aot(and through itDirectNAot, 21 MB) unconditionally, so every desktop head ships them, on every OS.WebView2Aotis generated with[GeneratedComInterface]. Its versioned interfaces form a 29-deep chain:ICoreWebView2_29 : ICoreWebView2_28, …, ICoreWebView2.TypeMapInfo.FindAndAddDefaultInterfaceImplementations;TypeMapInfo.AddRecursiveInterfaces;MarkStep.MarkBaseMethods.A stuck publish sits in
TypeMapInfo.FindAndAddDefaultInterfaceImplementations, recursing deeply. It's still there on current packages:Uno.Sdk 7.0.0-dev.113with ILLink 10.0.10, still running after 15 min at 4.2 GB.Isolating it
DirectN.dlllinked alone: 38 s whether all of it is rooted or just its public surface, soDirectNis not the problem.WebView2.dllrooted: still running after 5 minutes.DirectNas trimmable: still hangs.I1,I2 : I1, …I26 : I25,ILeaf : I26) anddotnet publish -p:PublishTrimmed=true. It takes 13 s at depth 22 and 92 s at depth 26, and keeps growing about 7× every 4 levels. Exact steps are in ILLink takes exponential time on deep interface hierarchies dotnet/runtime#136766.The ILLink fix (dotnet/runtime#136767)
The fix makes each of the three walks visit an interface, or an already-marked base method, once.
[GeneratedComInterface]chain, depth 20 × 10 methodsWebView2.dllrootedDirectN.dll21.9 → 2.6 MBmain,Mono.Linker.Testspasses (1307 passed, 0 failed), plus a newDeepInterfaceHierarchyregression test. That test passes in about 0.5 s; without the fix, the suite hits a 3-minute hang timeout.The Uno-side change (#25862)
WebViewUno Feature for WebView on-desktop. Heads without it now drop the three packages' assets after package resolution;UnoIncludeWebView2Aot=truekeeps them.Until the ILLink fix ships in a .NET servicing release, a desktop app that uses WebView and trims its publish stays blocked. Its only workaround is to disable trimming.
Xiaoy312 commentedon Nov 23, 2026
@ramezgerges #25862 doesn't seem to cover trimmed publish. A desktop head without WebView still hangs at "Optimizing assemblies for size" on Uno.Sdk 7.0.22 (uno.winui 7.0.65), which includes #25862.
Repro: a desktop head with
UnoFeatures=Skiaonly, noMicrosoft.Web.WebView2anywhere in the graph:ILLink ran for 2h+ and grew to ~20 GB before I stopped it. Stack samples show it in
MarkStep→TypeMapInfo.MapType→FindAndAddDefaultInterfaceImplementations, the walk from dotnet/runtime#136766.Why:
_UnoRemoveUnusedWebView2Aotremoves WebView2Aot/DirectNAot fromRuntimeCopyLocalItems/NativeCopyLocalItems. Their compile assets stay inReferencePath, becauseUno.UI.Runtime.Win32compiles against them. The ILLink task passes everyReferencePathitem it isn't linking as a reference:--action skiponly means the assembly isn't rewritten. ILLink still loads it, marks the WebView2 types thatUno.UI.Runtime.Win32touches, and builds their type maps, so the 29-deepICoreWebView2_*chain is walked anyway.Confirmed: the same ILLink invocation without the
WebView2,DirectNandDirectN.Extensionsreferences finishes in 9 s. The whole trimmed publish, with them removed fromReferencePathright before ILLink, takes ~13 s. There were no new warnings: only the two IL2104 summaries forUno.UI.Runtime.MacOSandUno.UI.Runtime.Win32, which are there either way. I haven't run the trimmed app.The workaround I used, which may also be the shape of a fix in
Uno.SingleProject.Desktop.targets:In the SDK, it would reuse
_UnoUnusedWebView2Packages(matching%(NuGetPackageId)) instead of hardcoding file names, so DirectN stays when something else owns it._RunILLinkis an SDK-internal target name, so hookingPrepareForILLinkmay be sturdier.ramezgerges commentedon Nov 24, 2026
@Xiaoy312 thanks, your analysis is right. #26696 fixes it.
#25862 was timed on its first revision, which also removed the WebView2Aot/DirectN compile assets, so ILLink never saw them (18 s). A later revision kept the compile assets so heads that use DirectN still compile, and I didn't re-time the trimmed publish after that change. The merged version hangs exactly as you describe. On the same machine today, the first revision publishes in 16 s and the merged one is still in ILLink after 10 minutes, so it isn't the Uno version or the .NET SDK.
#26696 takes the shape you suggested: after
PrepareForILLink, it removes the packages already listed in_UnoUnusedWebView2PackagesfromReferencePath, matched byNuGetPackageId, and puts them back afterILLink. Tested by repacking Uno.Sdk 7.0.22 with only that change, on a freshunoappdesktop head withUnoFeatures=Skia:TrimmerSingleWarn=false, only the existing IL2050 (UI Automation) and IL2026 (macOS WebView) warnings, none about the hidden assemblies.Apps that do use a WebView still need the ILLink fix (dotnet/runtime#136766) for a trimmed publish.