Repository navigation
fix(sdk): Leave out WebView2Aot assets when WebView is unused - #25862
MartinZikmund merged 6 commits into
Conversation
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
|
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 242857 found UI Test snapshots differences: Details
|
c5bdd14 to
94d5320
Compare
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 243341 found UI Test snapshots differences: Details
|
|
Heads-up: this PR and #25996 (approved, fix for #25216) both edit The conflict is textual only. Your new
There's no semantic conflict that I can see:
A side effect, not verified: removing |
|
@Mergifyio backport release/stable/7.0 |
✅ Backports have been createdDetails
|
94d5320 to
ca90519
Compare
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
Xiaoy312
left a comment
There was a problem hiding this comment.
Approving: dropping WebView2Aot/DirectN from heads that can't use a WebView is the right call, and the finalizer guard is correct. A few non-blocking follow-ups inline, the first two being the ones I'd most like addressed (here or in a follow-up):
- The keep-condition only sees the head's own feature/direct reference, so a transitively flowing
Microsoft.Web.WebView2(a library with theWebViewfeature, or a NuGet package depending on it) would now lose the WebView at runtime. - DirectNAot is stripped (including compile refs) even when the app references it directly.
- Without the assemblies, a WebView now fails with an assembly-load
FileNotFoundExceptioninstead of the clearerDllNotFoundExceptionforWebView2Loader.dll; a targeted message pointing at theWebViewUnoFeature /UnoIncludeWebView2Aotwould help. UnoIncludeWebView2Aotisn't documented yet;skia-libraries-trimming.md(next toUnoIncludeAllSkiaNativeLibraries) or the desktop section ofWebView.mdseem like the right homes.
CI: the Android shard 0/4 failures are the known Given_TextBox.When_Touch_*_Does_Not_Lock_ScrollViewer_Android pair, and the Android+NativeAOT failure is the NU1903 ILCompiler advisory at restore; neither is from this PR.
|
The build 243708 found UI Test snapshots differences: Details
|
78cc91f to
029cc17
Compare
The Win32 host references WebView2Aot, which pulls in DirectNAot. With trimming on, ILLink spends minutes or hangs walking their deep COM interface chains, so a trimmed desktop publish never finishes, even for apps that never create a WebView. Desktop heads without the documented `webview` feature now drop their assets after package resolution. `UnoIncludeWebView2Aot` keeps them. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A head can use WebView through a direct Microsoft.Web.WebView2 reference instead of the webview feature, as SamplesApp does. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A derived constructor that throws (WebView2Aot missing) leaves the base unconstructed, and its finalizer's NRE ends the process. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Keys the strip on WebView2Loader.dll being deployed, so a transitive Microsoft.Web.WebView2 reference keeps the WebView working too. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
DirectN is general-purpose interop: it is now left out only when the dependency graph shows WebView2Aot as its sole owner, and compile references are no longer removed. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Creating a WebView after the SDK left WebView2Aot out failed with a bare FileNotFoundException for an assembly the app never referenced. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 244090 found UI Test snapshots differences: Details
|
|
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. |
GitHub Issue: related to #24618
PR Type:
🐞 Bugfix
What changed? 🚀
A trimmed publish of a blank desktop app (
-p:PublishTrimmed=true) gets stuck at "Optimizing assemblies for size", even when the app never uses a WebView.Cause.
Uno.UI.Runtime.Win32referencesWebView2Aot(and through itDirectNAot) unconditionally, so every desktop head ships them. WebView2Aot's[GeneratedComInterface]chain is 29 interfaces deep (ICoreWebView2_29 : ICoreWebView2_28, …), and ILLink walks such chains exponentially. A dotnet/runtime issue and fix will be linked from #24618.Fix. A WebView needs
WebView2Loader.dllfromMicrosoft.Web.WebView2, which theWebViewUno Feature (required by the docs for WebView on-desktop), a direct reference or a transitive one deploys. Desktop heads that don't deploy it now leave out theWebView2Aotassets after package resolution.DirectNAotandDirectNAot.Extensionsare general-purpose interop, so they are left out too only when the dependency graph (the SDK'sResolvePackageDependencies) shows WebView2Aot as their sole owner; a head or library that uses DirectN itself keeps it, and compile references are never removed.UnoIncludeWebView2Aot=truekeeps everything.The host registers its WebView implementation through
ApiExtensibilityfactories, so those types load only when a WebView is created. An app without WebView starts normally without these assemblies.Keying on the deployed loader covers heads that reference
Microsoft.Web.WebView2directly or transitively instead of using the feature. SamplesApp references it directly, and an earlier version keyed on the feature alone crashed both Windows lanes inGiven_CoreWebView2Profile.Creating a WebView in an app where it was left out used to fail with a bare
FileNotFoundExceptionforWebView2. It now throws anInvalidOperationExceptionsaying WebView2 support was left out and to enable theWebViewUno Feature or referenceMicrosoft.Web.WebView2.That crash also exposed a finalizer bug. When
Win32NativeAotWebView's constructor fails (here becauseWebView2failed to load), the base constructor never ran. Its finalizer then dereferenced a nullPresenterand ended the process. The finalizer now skips an unconstructed instance.Apps with the
webviewfeature are unchanged. A trimmed publish of such an app still needs the ILLink fix.Validation (blank
net10.0-desktopapp onUno.Sdk 7.0.0-dev.113,dotnet publish -r win-x64 --self-contained -p:PublishTrimmed=true, with this target imported into the app):webviewfeatureDirectN/WebView2shipped; app starts and shows its windowwebviewfeature (build output)DirectN,DirectN.Extensions,WebView2presentSamplesApp desktop,
Given_CoreWebView2Profile+Given_CoreWebView2Environment: before, the app segfaults (Win32NativeWebViewBase.FinalizeNRE) and writes no results; after, 17/17 pass, withWebView2.dll/DirectN*.dllin the output.The trim warnings with the assemblies removed are the existing UI Automation (IL2050) and macOS WebView (IL2026) ones; none come from the missing assemblies.
Target logic, with a standalone head importing it (RID-less and
-r win-x64):webviewfeature, direct reference, or a class library referencingMicrosoft.Web.WebView2Error message: a SamplesApp desktop build with
WebView2/DirectNremoved from its output reports the newInvalidOperationExceptionwhenWebView2_Fixed_Heightcreates its WebView.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code