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
{{ message }}
Repository navigation
[Native AOT] [Gallery App] The webview component does not load in the Gallery app on Desktop when native aot is enabled. Other elements will no longer load in the app #23142
changed the title [-][Native AOT] [Gallery App] The webview component does not load in the Gallery app when native aot is enabled. Other elements will no longer load in the app[/-][+][Native AOT] [Gallery App] The webview component does not load in the Gallery app on Desktop when native aot is enabled. Other elements will no longer load in the app[/+]on Apr 27, 2026
(Which is a mismatch of Unix sed… but you get the idea).
What's interesting is that if we run Uno.Gallery.exeon PowerShell and pipe output to Out-Default so that it's visible, we see an error message after clicking on UI components > WebView:
> .\Uno.Gallery\bin\Release\net10.0-desktop\win-arm64\publish\Uno.Gallery.exe|Out-Default
fail: Uno.UI.Dispatching.NativeDispatcher[0]
NativeDispatcher unhandled exception
System.NotSupportedException: COM Interop requires ComWrapper instance registered for marshalling.
at System.Runtime.InteropServices.ComWrappers.ComInterfaceForObject(Object) +0xa4
at System.Runtime.InteropServices.ComWrappers.ComInterfaceForObject(Object, Guid) +0x24
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateCoreWebView2EnvironmentWithOptions(String, String, ICoreWebView2EnvironmentOptions, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler) +0xdc
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.<CreateAsync>d__102.MoveNext() +0xe4---End of stack trace from previous location ---
at Uno.UI.Runtime.Skia.Win32.Win32NativeWebView.<>c__DisplayClass15_0.<<-ctor>b__0>d.MoveNext() +0x60---End of stack trace from previous location ---
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__124_0(Object state) +0x1c
at Uno.UI.Dispatching.NativeDispatcher.RunAction(NativeDispatcher, Action) +0x8c
which shows the actual problem: Native AOT and COM interop do not currently mix out-of-the-box. Which is somewhat problematic when WebView is built entirely around COM interop on Windows…
Some cursory investigation suggests that this may not be blocker; the "ComWrappers API" is mentioned as an "AOT-friendly COM interop solution" in Tutorial: Use the ComWrappers API.
$ dotnet publish -c Release -r linux-arm64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop \
-bl Uno.Gallery/Uno.Gallery.csproj -p:SelfContained=true -p:UseSkiaRendering=true \
-p:SkiaPublishAot=true -p:IsAotCompatible=true
$ ./Uno.Gallery/bin/Release/net10.0-desktop/linux-arm64/publish/Uno.Gallery
…
fail: Uno.UI.Dispatching.NativeDispatcher[0]
NativeDispatcher unhandled exception
System.PlatformNotSupportedException: libwebkit2gtk-4.0 is not found. Make sure that WebKit2GTK 4.0 and GTK 3 are installed. See https://aka.platform.uno/webview2 for more information
at Uno.UI.WebView.Skia.X11.X11NativeWebView..ctor(CoreWebView2, ContentPresenter) + 0x2ac
at Microsoft.Web.WebView2.Core.CoreWebView2.GetNativeWebViewFromTemplate() + 0x13c
at Microsoft.Web.WebView2.Core.CoreWebView2.OnOwnerApplyTemplate() + 0x20
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x324
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.ContentPresenter.MeasureOverride(Size) + 0xbc
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Control.MeasureOverride(Size) + 0x50
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.ContentPresenter.MeasureOverride(Size) + 0xbc
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x87c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8
at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x33c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8
at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x33c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8
at Microsoft.UI.Xaml.Controls.Control.MeasureOverride(Size) + 0x50
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x87c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8
at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x33c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8
at Uno.UI.Xaml.Islands.XamlIslandRoot.MeasureOverride(Size) + 0x1fc
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.UpdateLayout() + 0x700
at Uno.UI.Xaml.Core.CoreServices.OnTick() + 0x1c4
at Uno.UI.Dispatching.NativeDispatcher.RunAction(NativeDispatcher, Action) + 0x8c
There are several issues here:
The distro I'm using doesn't even havelibwebkit2gtk-4.0!
unoplatform/uno doesn't uselibwebkit2gtk-4.0 either! It uses libwebkit2gtk-4.1!
It also requires development packages, so install one:
sudo apt install libwebkit2gtk-4.1-dev
After re-run the app, it fails worse: instead of an exception logged to stdout (see above) and the app keeps running, the app instead crashes after clicking UI components > WebView:
fail: Uno.UI.Dispatching.NativeDispatcher[0]
NativeDispatcher unhandled exception
System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
---> System.NullReferenceException: Couldn't find GLibrary in WebKitGtkSharp
at Uno.UI.WebView.Skia.X11.X11NativeWebView..cctor() + 0x31c
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xb4
--- End of inner exception stack trace ---
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x15c
at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnGCStaticBase(StaticClassConstructionContext*, Object) + 0x14
at Uno.UI.WebView.Skia.X11.X11NativeWebView..ctor(CoreWebView2, ContentPresenter) + 0x284
at Microsoft.Web.WebView2.Core.CoreWebView2.GetNativeWebViewFromTemplate() + 0x13c
at Microsoft.Web.WebView2.Core.CoreWebView2.OnOwnerApplyTemplate() + 0x20
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x324
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.ContentPresenter.MeasureOverride(Size) + 0xbc
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Grid.MeasureCell(UIElement, Grid.CellUnitTypes, Grid.CellUnitTypes, Boolean, Double, Double) + 0xfc
at Microsoft.UI.Xaml.Controls.Grid.MeasureCellsGroup(Int32, Int32, Double, Double, Boolean, Boolean, Grid.CellCacheStackVector&) + 0xb0
at Microsoft.UI.Xaml.Controls.Grid.MeasureOverride(Size) + 0x2c0
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Control.MeasureOverride(Size) + 0x50
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Grid.MeasureCell(UIElement, Grid.CellUnitTypes, Grid.CellUnitTypes, Boolean, Double, Double) + 0xfc
at Microsoft.UI.Xaml.Controls.Grid.MeasureCellsGroup(Int32, Int32, Double, Double, Boolean, Boolean, Grid.CellCacheStackVector&) + 0xb0
at Microsoft.UI.Xaml.Controls.Grid.MeasureOverride(Size) + 0x2c0
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.Controls.StackPanel.MeasureOverride(Size) + 0x330
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Control.MeasureOverride(Size) + 0x50
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.Controls.Grid.MeasureOverride(Size) + 0x5b8
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.Controls.Grid.MeasureOverride(Size) + 0x5b8
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.ContentPresenter.MeasureOverride(Size) + 0xbc
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.Controls.Grid.MeasureOverride(Size) + 0x5b8
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.Controls.StackPanel.MeasureOverride(Size) + 0x330
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Grid.MeasureCell(UIElement, Grid.CellUnitTypes, Grid.CellUnitTypes, Boolean, Double, Double) + 0xfc
at Microsoft.UI.Xaml.Controls.Grid.MeasureCellsGroup(Int32, Int32, Double, Double, Boolean, Boolean, Grid.CellCacheStackVector&) + 0xb0
at Microsoft.UI.Xaml.Controls.Grid.MeasureOverride(Size) + 0x2c0
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.ScrollContentPresenter.MeasureOverride(Size) + 0x210
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Grid.MeasureCell(UIElement, Grid.CellUnitTypes, Grid.CellUnitTypes, Boolean, Double, Double) + 0xfc
at Microsoft.UI.Xaml.Controls.Grid.MeasureCellsGroup(Int32, Int32, Double, Double, Boolean, Boolean, Grid.CellCacheStackVector&) + 0xb0
at Microsoft.UI.Xaml.Controls.Grid.MeasureOverride(Size) + 0x370
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Border.MeasureOverride(Size) + 0x90
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Control.MeasureOverride(Size) + 0x50
at Microsoft.UI.Xaml.Controls.ScrollViewer.MeasureOverride(Size) + 0x14
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Grid.MeasureCell(UIElement, Grid.CellUnitTypes, Grid.CellUnitTypes, Boolean, Double, Double) + 0xfc
at Microsoft.UI.Xaml.Controls.Grid.MeasureCellsGroup(Int32, Int32, Double, Double, Boolean, Boolean, Grid.CellCacheStackVector&) + 0xb0
at Microsoft.UI.Xaml.Controls.Grid.MeasureOverride(Size) + 0x370
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Control.MeasureOverride(Size) + 0x50
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.Controls.Grid.MeasureOverride(Size) + 0x5b8
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.Control.MeasureOverride(Size) + 0x50
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0
at Microsoft.UI.Xaml.Controls.ContentPresenter.MeasureOverride(Size) + 0xbc
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x87c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8
at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x33c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8
at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x33c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8
at Microsoft.UI.Xaml.Controls.Control.MeasureOverride(Size) + 0x50
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x87c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8
at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x33c
at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8
at Uno.UI.Xaml.Islands.XamlIslandRoot.MeasureOverride(Size) + 0x1fc
at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c
at Microsoft.UI.Xaml.UIElement.UpdateLayout() + 0x700
at Uno.UI.Xaml.Core.CoreServices.OnTick() + 0x1c4
at Uno.UI.Dispatching.NativeDispatcher.RunAction(NativeDispatcher, Action) + 0x8c
Unhandled exception. System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
---> System.NullReferenceException: Couldn't find GLibrary in WebKitGtkSharp
at Uno.UI.WebView.Skia.X11.X11NativeWebView..cctor() + 0x31c
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xb4
--- End of inner exception stack trace ---
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xc0
at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnGCStaticBase(StaticClassConstructionContext*, Object) + 0x14
at Uno.UI.WebView.Skia.X11.X11NativeWebView.RunOnGtkThread(Action) + 0x110
at Uno.UI.WebView.Skia.X11.X11NativeWebView.Finalize() + 0x30
at System.Runtime.__Finalizer.DrainQueue() + 0x54
at System.Runtime.__Finalizer.ProcessFinalizers() + 0x8c
Aborted (core dumped)
Part of the issue is probably that Native AOT doesn't like Assembly.Load(), and the X11 backend uses Assembly.Load():
FieldInfofield=glibraryType.GetField("_libraries",BindingFlags.NonPublic|BindingFlags.Static)??thrownewNullReferenceException("Couldn't find a field named _libraries in GLibrary");
objectlibraries=field.GetValue(null)??thrownewNullReferenceException("Couldn't read the static field named _libraries in GLibrary");
varsetItemMethod=libraries.GetType().GetMethod("set_Item")??thrownewNullReferenceException("Couldn't find a method named set_Item in _libraries");
Part of the problem is that WebBrowser doesn't work on my Linux VM. If I build "normally" for Skia+CoreCLR, it crashes:
$ git clean -xdf
$ dotnet publish -c Release -r linux-arm64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop \
-bl Uno.Gallery/Uno.Gallery.csproj -p:SelfContained=true -p:UseSkiaRendering=true
$ ./Uno.Gallery/bin/Release/net10.0-desktop/linux-arm64/publish/Uno.Gallery
fail: Uno.WinUI.Runtime.Skia.X11.X11NativeOverlappedPresenter[0]
Couldn't get OverlappedPresenterState: _NET_WM_STATE does not exist on the window. Make sure you use an EWMH-compliant WM.fail: Uno.WinUI.Runtime.Skia.X11.X11NativeOverlappedPresenter[0] Couldn't get OverlappedPresenterState: _NET_WM_STATE does not exist on the window. Make sure you use an EWMH-compliant WM.
(Uno.Gallery:8586): Gdk-CRITICAL **: 14:46:16.851: gdk_x11_window_get_xid: assertion 'GDK_IS_X11_WINDOW (window)' failed
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 3 (X_GetWindowAttributes)
Resource id in failed request: 0x0
Serial number of failed request: 103
Current serial number in output stream: 104
After far too long spinning my wheels, I have the beginnings of an understanding for what's going wrong.
After building Uno.Gallery.csprojas described above, .\Uno.Gallery\obj\Release\net10.0-desktop\win-arm64\native\Uno.Gallery.ilc.rsp contains this fragment:
These are the only mentions of WebView2 within Uno.Gallery.ilc.rsp.
Of some curiosity is that we're referencing netcoreapp3.0\Microsoft.Web.WebView2.WinForms.dll.
Meanwhile, open C:\Users\Jon\.nuget\packages\microsoft.web.webview2\1.0.3912.50\lib_manual, and see this other assembly: net8.0-windows10.0.17763.0\Microsoft.Web.WebView2.Core.Projection.dll.
Theory (unvalidated): If we get Microsoft.Web.WebView2.Core.Projection.dll into *.ilc.rsp, the WebView will work.
I think the short version is that this will not work, and cannot work.
(…then there's the fact that "just referencing" Microsoft.Web.WebView2.Core.Projection.dll results in lots of build errors, as both Microsoft.Web.WebView2.Core.Projection.dllandUno.UI.dll provide the type Microsoft.Web.WebView2.Core.CoreWebView2, and solving that introduces build errors from IlcCompile because WinRT.Runtime.dll can't be found, and trying to fix that makes me rethink everything…)
but I don't think we want to rebuild it or ship it.
Furthermore, the existing "pre-built" version of WinRT.Runtime.dll is part of the Microsoft.Windows.CsWinRT NuGet Package, but the assemblies target net8.0-windows, and that -windows is important: it's specific to Windows, and is not usable from e.g. net10.0-desktop, which is what we're building Uno.Gallery with.
What I believe to be the case is that, while Microsoft.Web.WebView2 says it works with Native AOT, it only works with Native AOT when targeting WinUI3. WinForms and WPF are not supported (attempting to build a WinForms app for Native AOT results in a NETSDK1175 error; attempting to build a WPF app for Native AOT results in a NETSDK1168 error). There are "two" assemblies which provide C# bindings to WebView2:
Microsoft.Web.WebView2.Core.dll: Does not support Native AOT. Uses "runtime-based"/"legacy" COM Interop. Usable from WinForms and WPF. Used by Uno's Uno.UI.Runtime.Skia.Win32 implementation. .
Microsoft.Web.WebView2.Core.Projection.dll: Supports Native AOT. Only usable by WinRT / WinUI.
Apparently there are multiple "types" of .winmd files, including (at least?) "Win32Metadata" and WinRT variants.
The Microsoft.Web.WebView2.Core.winmd file included in the Microsoft.Web.Webview2 1.0.3967.48 package is of the WinRT variety, meaning cswin32 cannot emit COM interfaces from that input.
Perhaps microsoft/win32metadata could be used to produce a cswin32-compatable .winmd file for cswin32?
-p:IlcGenerateMstatFile=true generates a .mstat file, which is an assembly which references all assemblies and types and methods/etc. that are actually used by the Native AOT app. We can thus interrogate it to see what assemblies were actually used:
Claude in #23351 nicely came up with an implementation which uses smourier/WebView2Aot, and with some local hacking it works. I need to finish up the PR and try testing the actual NuGet packages to see if it actually works.
Activity
[-][Native AOT] [Gallery App] The webview component does not load in the Gallery app when native aot is enabled. Other elements will no longer load in the app[/-][+][Native AOT] [Gallery App] The webview component does not load in the Gallery app on Desktop when native aot is enabled. Other elements will no longer load in the app[/+]jonpryor commentedon Apr 27, 2026
khaskoul mentioned that this happens with Uno.Sdk 6.6.0-dev.216.
In PowerShell terms:
(Which is a mismatch of Unix
sed… but you get the idea).What's interesting is that if we run
Uno.Gallery.exeon PowerShell and pipe output toOut-Defaultso that it's visible, we see an error message after clicking on UI components > WebView:which shows the actual problem: Native AOT and COM interop do not currently mix out-of-the-box. Which is somewhat problematic when WebView is built entirely around COM interop on Windows…
Specifically, from Limitations of Native AOT deployment:
Some cursory investigation suggests that this may not be blocker; the "
ComWrappersAPI" is mentioned as an "AOT-friendly COM interop solution" in Tutorial: Use theComWrappersAPI.There is also Source generation for ComWrappers.
I will need to look into using the
ComWrappersAPI to supportWebView.jonpryor commentedon Apr 27, 2026
Additionally, UI components > WebView works as expected (for me) on macOS:
jonpryor commentedon Apr 27, 2026
Linux does not work for me:
$ dotnet publish -c Release -r linux-arm64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop \ -bl Uno.Gallery/Uno.Gallery.csproj -p:SelfContained=true -p:UseSkiaRendering=true \ -p:SkiaPublishAot=true -p:IsAotCompatible=true $ ./Uno.Gallery/bin/Release/net10.0-desktop/linux-arm64/publish/Uno.Gallery … fail: Uno.UI.Dispatching.NativeDispatcher[0] NativeDispatcher unhandled exception System.PlatformNotSupportedException: libwebkit2gtk-4.0 is not found. Make sure that WebKit2GTK 4.0 and GTK 3 are installed. See https://aka.platform.uno/webview2 for more information at Uno.UI.WebView.Skia.X11.X11NativeWebView..ctor(CoreWebView2, ContentPresenter) + 0x2ac at Microsoft.Web.WebView2.Core.CoreWebView2.GetNativeWebViewFromTemplate() + 0x13c at Microsoft.Web.WebView2.Core.CoreWebView2.OnOwnerApplyTemplate() + 0x20 at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x324 at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0 at Microsoft.UI.Xaml.Controls.ContentPresenter.MeasureOverride(Size) + 0xbc at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0 at Microsoft.UI.Xaml.Controls.Control.MeasureOverride(Size) + 0x50 at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x2f0 at Microsoft.UI.Xaml.Controls.ContentPresenter.MeasureOverride(Size) + 0xbc at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x87c at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8 at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x33c at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8 at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x33c at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8 at Microsoft.UI.Xaml.Controls.Control.MeasureOverride(Size) + 0x50 at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x87c at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8 at Microsoft.UI.Xaml.UIElement.DoMeasure(Size) + 0x33c at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize) + 0x1d8 at Uno.UI.Xaml.Islands.XamlIslandRoot.MeasureOverride(Size) + 0x1fc at Microsoft.UI.Xaml.FrameworkElement.InnerMeasureCore(Size) + 0x46c at Microsoft.UI.Xaml.UIElement.UpdateLayout() + 0x700 at Uno.UI.Xaml.Core.CoreServices.OnTick() + 0x1c4 at Uno.UI.Dispatching.NativeDispatcher.RunAction(NativeDispatcher, Action) + 0x8cThere are several issues here:
The distro I'm using doesn't even have
libwebkit2gtk-4.0!unoplatform/uno doesn't use
libwebkit2gtk-4.0either! It useslibwebkit2gtk-4.1!uno/src/AddIns/Uno.UI.WebView.Skia.X11/X11NativeWebView.cs
Line 56 in c507882
It also requires development packages, so install one:
After re-run the app, it fails worse: instead of an exception logged to
stdout(see above) and the app keeps running, the app instead crashes after clicking UI components > WebView:Part of the issue is probably that Native AOT doesn't like
Assembly.Load(), and the X11 backend usesAssembly.Load():uno/src/AddIns/Uno.UI.WebView.Skia.X11/X11NativeWebView.cs
Lines 83 to 90 in c507882
Part of the problem is that WebBrowser doesn't work on my Linux VM. If I build "normally" for Skia+CoreCLR, it crashes:
$ git clean -xdf $ dotnet publish -c Release -r linux-arm64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop \ -bl Uno.Gallery/Uno.Gallery.csproj -p:SelfContained=true -p:UseSkiaRendering=true $ ./Uno.Gallery/bin/Release/net10.0-desktop/linux-arm64/publish/Uno.Gallery fail: Uno.WinUI.Runtime.Skia.X11.X11NativeOverlappedPresenter[0] Couldn't get OverlappedPresenterState: _NET_WM_STATE does not exist on the window. Make sure you use an EWMH-compliant WM. fail: Uno.WinUI.Runtime.Skia.X11.X11NativeOverlappedPresenter[0] Couldn't get OverlappedPresenterState: _NET_WM_STATE does not exist on the window. Make sure you use an EWMH-compliant WM. (Uno.Gallery:8586): Gdk-CRITICAL **: 14:46:16.851: gdk_x11_window_get_xid: assertion 'GDK_IS_X11_WINDOW (window)' failed X Error of failed request: BadWindow (invalid Window parameter) Major opcode of failed request: 3 (X_GetWindowAttributes) Resource id in failed request: 0x0 Serial number of failed request: 103 Current serial number in output stream: 104I'm not sure what's going on here.
jonpryor commentedon May 1, 2026
Back on "
WebView2+ Native AOT + Windows" beat…The crash isn't in Uno code; it's crashing in Microsoft.Web.WebView2.
What's odd is that it seemingly should work? Consider:
The suggestion from Google AI is that with a Microsoft.WindowsAppSDK >= 1.6 and WebView2 >= 1.0.2849.39 should work.
My local build of Uno.Gallery is using Microsoft.WindowsAppSDK 1.8.260101001 and WebView2 1.0.3912.50.
So those versions don't work, at least not here.
Still investigating…
jonpryor commentedon May 6, 2026
After far too long spinning my wheels, I have the beginnings of an understanding for what's going wrong.
After building
Uno.Gallery.csprojas described above,.\Uno.Gallery\obj\Release\net10.0-desktop\win-arm64\native\Uno.Gallery.ilc.rspcontains this fragment:These are the only mentions of
WebView2withinUno.Gallery.ilc.rsp.Of some curiosity is that we're referencing
netcoreapp3.0\Microsoft.Web.WebView2.WinForms.dll.Meanwhile, open
C:\Users\Jon\.nuget\packages\microsoft.web.webview2\1.0.3912.50\lib_manual, and see this other assembly:net8.0-windows10.0.17763.0\Microsoft.Web.WebView2.Core.Projection.dll."Projection" makes me think that this is related to COM support; see also Tutorial: Use the
ComWrappersAPI.Disassemble
net8.0-windows10.0.17763.0\Microsoft.Web.WebView2.Core.Projection.dll, and it contains the two things I'm looking for:Mention of
ComWrappers(though not in exactly how the above Tutorial mentions usage; perhaps the tutorial is old?)Use of
[GuidAttribute]on interfaces, as mentioned in the Source Generator COM feature doc:Theory (largely validated):
Microsoft.Web.WebView2.Core.Projection.dllcontains the "ComWrapper instance required for marshaling".Theory (unvalidated): If we get
Microsoft.Web.WebView2.Core.Projection.dllinto*.ilc.rsp, the WebView will work.jonpryor commentedon May 6, 2026
Last time, I thought:
I think the short version is that this will not work, and cannot work.
(…then there's the fact that "just referencing"
Microsoft.Web.WebView2.Core.Projection.dllresults in lots of build errors, as bothMicrosoft.Web.WebView2.Core.Projection.dllandUno.UI.dllprovide the typeMicrosoft.Web.WebView2.Core.CoreWebView2, and solving that introduces build errors fromIlcCompilebecauseWinRT.Runtime.dllcan't be found, and trying to fix that makes me rethink everything…)Observe the IL from the previous comment:
This requires an assembly reference to
WinRT.Runtime, to use the methodWinRT.ComWrappersSupport.RegisterObjectForInterface(object, nint).Uno doesn't have a copy of this assembly, nor does it reimplement it.
WinRT.Runtimeis open-source, under MIT, available at: https://github.com/microsoft/CsWinRT/tree/10d2b9d2a3e219df5c44ab8f567f6049dfb72cd0/src/WinRT.Runtimebut I don't think we want to rebuild it or ship it.
Furthermore, the existing "pre-built" version of
WinRT.Runtime.dllis part of the Microsoft.Windows.CsWinRT NuGet Package, but the assemblies targetnet8.0-windows, and that-windowsis important: it's specific to Windows, and is not usable from e.g.net10.0-desktop, which is what we're building Uno.Gallery with.What I believe to be the case is that, while Microsoft.Web.WebView2 says it works with Native AOT, it only works with Native AOT when targeting WinUI3. WinForms and WPF are not supported (attempting to build a WinForms app for Native AOT results in a NETSDK1175 error; attempting to build a WPF app for Native AOT results in a NETSDK1168 error). There are "two" assemblies which provide C# bindings to WebView2:
Microsoft.Web.WebView2.Core.dll: Does not support Native AOT. Uses "runtime-based"/"legacy" COM Interop. Usable from WinForms and WPF. Used by Uno'sUno.UI.Runtime.Skia.Win32implementation. .Microsoft.Web.WebView2.Core.Projection.dll: Supports Native AOT. Only usable by WinRT / WinUI.jonpryor commentedon May 6, 2026
The previous investigation leaves only one question: where do we go from here?
It looks like the only path forward is to do our own binding of the underlying COM APIs: https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/?view=webview2-1.0.3856.49
Hopefully dotnet/runtime has some updated tooling to automate this process.
Or look into https://github.com/smourier/WebView2Aot.
jonpryor commentedon May 13, 2026
It also looks like microsoft/cswin32 will emit COM interfaces:
jonpryor commentedon May 20, 2026
@jonpryor wrote:
Just because cswin32 can emit COM interfaces does not mean that it will work for
ICoreWebView2:Apparently there are multiple "types" of
.winmdfiles, including (at least?) "Win32Metadata" and WinRT variants.The
Microsoft.Web.WebView2.Core.winmdfile included in the Microsoft.Web.Webview2 1.0.3967.48 package is of the WinRT variety, meaning cswin32 cannot emit COM interfaces from that input.Perhaps microsoft/win32metadata could be used to produce a cswin32-compatable
.winmdfile for cswin32?Or this is more evidence that we should just stick with https://github.com/smourier/WebView2Aot.
jonpryor commentedon May 28, 2026
PR #23225 was an attempt to update the
Uno.UI.Runtime.Skia.Wpfassembly to use smourier/WebView2Aot, and @MartinZikmund noted that:Which raises a new-to-me question: what is Uno.Gallery using for WebView2?
Let's update the previous build instructions to use
-p:IlcGenerateMstatFile=true:-p:IlcGenerateMstatFile=truegenerates a.mstatfile, which is an assembly which references all assemblies and types and methods/etc. that are actually used by the Native AOT app. We can thus interrogate it to see what assemblies were actually used:Indeed,
Uno.UI.Runtime.Skia.Wpfis not used.Microsoft.Web.WebView2.Coreis used:which is "of course" the problem:
Microsoft.Web.WebView2.Coreuses "classic" COM Interop, which isn't supported by Native AOT.At least I know which assembly needs updating now…
jonpryor commentedon Jun 8, 2026
Claude in #23351 nicely came up with an implementation which uses smourier/WebView2Aot, and with some local hacking it works. I need to finish up the PR and try testing the actual NuGet packages to see if it actually works.
feat(win32): WebView2Aot backend for <WebView2/>
feat(win32): WebView2Aot backend for <WebView2/>
khaskoul commentedon Jul 31, 2026
Fix verified with:
Templates/SDK: 6.7.0-dev.129
Platform(s): Desktop
VS VSIX: 6.7-dev.14
IDE: VS 18.4.6
OS: Windows