Skip to content

Trimmed Skia Desktop publish hangs #24618

In review
In review

Description

@jpnurmi

Current behavior 🐛

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:

dotnet publish UnoPublishRepro/UnoPublishRepro.csproj \
  -c Release -f net10.0-desktop -r linux-x64 --self-contained true \
  -p:TargetFrameworks=net10.0-desktop -p:PublishTrimmed=true -v minimal

The publish completes when Uno.Sdk is set to 6.6.42 instead.

Workaround 🛠️

The issue can be avoided by using Uno.Sdk 6.6.42 or disabling trimming.

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

Build tasks, Desktop (X11), Desktop (macOS), Desktop (Windows)

Uno.Sdk version (and other relevant versions) 📦

Affected: 6.7.18. Works: 6.6.42.

IDE version 🧑‍💻

N/A (.NET CLI)

Anything else we need to know? 💬

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.

Activity

  1. added
    triage/untriaged
    on Sep 23, 2026
  2. added theissue type on Sep 23, 2026
  3. added
    7.0
    on Oct 14, 2026
  4. removed
    triage/untriaged
    7.0
    on Oct 29, 2026
  5. self-assigned this
    on Oct 31, 2026
  6. ramezgerges commented on Oct 31, 2026

    @ramezgerges
    Contributor

    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:

    What happens

    • 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:
      • 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.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.
    • ILLink 11.0.0-rc.2: behaves the same.

    The ILLink fix (dotnet/runtime#136767)

    The fix makes each of the three walks visit an interface, or an already-marked base method, once.

    Case Stock ILLink 10.0.10 Patched
    [GeneratedComInterface] chain, depth 20 × 10 methods > 240 s (killed) 3.5 s
    Same, depth 29 hang 5.4 s
    WebView2.dll rooted > 300 s (killed) 9 s; DirectN.dll 21.9 → 2.6 MB
    Blank Uno desktop app, trimmed publish > 15 min (killed) 24 s; app starts
    • 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 Uno-side change (#25862)

    • 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.

  7. Xiaoy312 commented on Nov 23, 2026

    @Xiaoy312
    Contributor

    @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:

    dotnet publish -f net10.0-desktop -r win-x64 --self-contained -p:PublishTrimmed=true

    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:

    -reference "...\webview2aot\1.5.0\lib\net10.0\WebView2.dll"
    --action skip "WebView2"
    

    --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:

    <Target Name="HideWebView2FromILLink" BeforeTargets="_RunILLink">
      <ItemGroup>
        <_HiddenReference Include="@(ReferencePath)" Condition="'%(Filename)' == 'WebView2' or '%(Filename)' == 'DirectN' or '%(Filename)' == 'DirectN.Extensions'" />
        <ReferencePath Remove="@(_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.

  8. ramezgerges commented on Nov 24, 2026

    @ramezgerges
    Contributor

    @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 _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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions