Repository navigation
fix(sdk): Leave out WebView2Aot assets when WebView is unused (backport #25862) - #26131
Closed
mergify[bot] wants to merge 6 commits into
Closed
mergify[bot] wants to merge 6 commits into
mergify[bot] wants to merge 6 commits into
Conversation
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]> (cherry picked from commit fd9a94e)
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]> (cherry picked from commit f9d365a)
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]> (cherry picked from commit 88e5b09)
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]> (cherry picked from commit 8189c70)
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]> (cherry picked from commit 6c69b61)
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]> (cherry picked from commit 029cc17)
1 of 5 tasks
Contributor
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
This is an automatic backport of pull request #25862 done by [Mergify](https://mergify.com).