Skip to content

[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

Closed

Description

@khaskoul

Current behavior 🐛

Recording.2026-04-27.132200.mp4

The webview component does not load and all other elements will no longer become visible

Expected behavior 🎯

Webviews load the user can still access all other components

How to reproduce it (as minimally and precisely as possible) 🔬

  1. Launch Uno Gallery with Native AOT enabled
  2. Expand the UI features section
  3. Select any UI Component (Other than webview)
  4. Go to Webview
  5. Observe that the webview element is not loaded
  6. Attempt to navigate to any other page
  7. Observe that the elements no longer load
  8. Attempt to collapse sections in the navigation bar
  9. Observe that the sections do not appear to fully collapse but their child items are not visible

Workaround 🛠️

No response

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

No response

Uno.Sdk version (and other relevant versions) 📦

uno.sdk: 6.6.0-dev.216

IDE version 🧑‍💻

VS Code 1.117.0

Anything else we need to know? 💬

No response

Activity

  1. added
    triage/untriaged
    on Apr 27, 2026
  2. added theissue type on Apr 27, 2026
  3. 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
  4. jonpryor commented on Apr 27, 2026

    @jonpryor
    Contributor

    khaskoul mentioned that this happens with Uno.Sdk 6.6.0-dev.216.

    In PowerShell terms:

    git clone https://github.com/unoplatform/Uno.Gallery.git
    cd Uno.Gallery
    git checkout 54a08b1587aa020a5651d61eb3a3023a79e89d72
    sed -i '' 's/"Uno.Sdk": ".*"/"Uno.Sdk": "6.6.0-dev.216"/g' global.json
    dotnet publish -c Release -r win-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
    

    (Which is a mismatch of Unix sed… but you get the idea).

    What's interesting is that if we run Uno.Gallery.exe on 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…

    Specifically, from Limitations of Native AOT deployment:

    • Windows: No built-in COM.

    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.

    There is also Source generation for ComWrappers.

    I will need to look into using the ComWrappers API to support WebView.

  5. jonpryor commented on Apr 27, 2026

    @jonpryor
    Contributor

    Additionally, UI components > WebView works as expected (for me) on macOS:

    dotnet publish -c Release -r osx-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 \
      -p:TrimmerSingleWarn=false -p:_ExtraTrimmerArgs=--verbose \
      -p:IlcGenerateMetadataLog=true -p:IlcGenerateMstatFile=true
    
    ./Uno.Gallery/bin/Release/net10.0-desktop/osx-arm64/publish/Uno.Gallery
    Image
  6. jonpryor commented on Apr 27, 2026

    @jonpryor
    Contributor

    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) + 0x8c
    
    Image

    There are several issues here:

    1. The distro I'm using doesn't even have libwebkit2gtk-4.0!

    2. unoplatform/uno doesn't use libwebkit2gtk-4.0 either! It uses libwebkit2gtk-4.1!

      [DllImport("libwebkit2gtk-4.1.so", CallingConvention = CallingConvention.Cdecl)]

    3. 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():

    Assembly assembly = Assembly.Load("WebKitGtkSharp");
    Type glibraryType = assembly.GetType("GLibrary") ?? throw new NullReferenceException("Couldn't find GLibrary in WebKitGtkSharp");
    Type libraryType = assembly.GetType("Library") ?? throw new NullReferenceException("Couldn't find Library in WebKitGtkSharp");
    object webkitLibraryEnum = Enum.ToObject(libraryType, 11);
    FieldInfo field = glibraryType.GetField("_libraries", BindingFlags.NonPublic | BindingFlags.Static) ?? throw new NullReferenceException("Couldn't find a field named _libraries in GLibrary");
    object libraries = field.GetValue(null) ?? throw new NullReferenceException("Couldn't read the static field named _libraries in GLibrary");
    var setItemMethod = libraries.GetType().GetMethod("set_Item") ?? throw new NullReferenceException("Couldn't find a method named set_Item in _libraries");
    setItemMethod.Invoke(libraries, [webkitLibraryEnum, webkitgtk41handle]);

    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

    I'm not sure what's going on here.

  7. jonpryor commented on May 1, 2026

    @jonpryor
    Contributor

    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…

  8. jonpryor commented on May 6, 2026

    @jonpryor
    Contributor

    After far too long spinning my wheels, I have the beginnings of an understanding for what's going wrong.

    After building Uno.Gallery.csproj as described above, .\Uno.Gallery\obj\Release\net10.0-desktop\win-arm64\native\Uno.Gallery.ilc.rsp contains this fragment:

    -r:C:\Users\jon\.nuget\packages\microsoft.web.webview2\1.0.3912.50\lib_manual\netcoreapp3.0\Microsoft.Web.WebView2.Core.dll
    -r:C:\Users\jon\.nuget\packages\microsoft.web.webview2\1.0.3912.50\lib_manual\netcoreapp3.0\Microsoft.Web.WebView2.WinForms.dll
    

    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.

    "Projection" makes me think that this is related to COM support; see also Tutorial: Use the ComWrappers API.

    Disassemble net8.0-windows10.0.17763.0\Microsoft.Web.WebView2.Core.Projection.dll, and it contains the two things I'm looking for:

    1. Mention of ComWrappers (though not in exactly how the above Tutorial mentions usage; perhaps the tutorial is old?)

          IL_0034:  call       instance native int Microsoft.Web.WebView2.Core.CoreWebView2CustomSchemeRegistration::get_ThisPtr()
          IL_0039:  call       void [WinRT.Runtime]WinRT.ComWrappersSupport::RegisterObjectForInterface(object,
                                                                                                        native int)
    2. Use of [GuidAttribute] on interfaces, as mentioned in the Source Generator COM feature doc:

      .class interface private abstract auto ansi beforefieldinit Microsoft.Web.WebView2.Core.CoreWebView2Profile_Manual
      {
        .custom instance void [System.Runtime.InteropServices]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 42 34 32 42 46 41 42 34 2D 43 34 42 46   // ..$B42BFAB4-C4BF
                                                                                                                              2D 35 34 36 39 2D 38 39 41 43 2D 43 41 44 43 36   // -5469-89AC-CADC6
                                                                                                                              39 45 33 42 30 46 35 00 00 )                      // 9E3B0F5..

    Theory (largely validated): Microsoft.Web.WebView2.Core.Projection.dll contains the "ComWrapper instance required for marshaling".

    Theory (unvalidated): If we get Microsoft.Web.WebView2.Core.Projection.dll into *.ilc.rsp, the WebView will work.

  9. jonpryor commented on May 6, 2026

    @jonpryor
    Contributor

    Last time, I thought:

    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.dll and Uno.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…)

    Observe the IL from the previous comment:

        IL_0039:  call       void [WinRT.Runtime]WinRT.ComWrappersSupport::RegisterObjectForInterface(object, native int)

    This requires an assembly reference to WinRT.Runtime, to use the method WinRT.ComWrappersSupport.RegisterObjectForInterface(object, nint).

    Uno doesn't have a copy of this assembly, nor does it reimplement it.

    WinRT.Runtime is open-source, under MIT, available at: https://github.com/microsoft/CsWinRT/tree/10d2b9d2a3e219df5c44ab8f567f6049dfb72cd0/src/WinRT.Runtime

    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.
  10. jonpryor commented on May 6, 2026

    @jonpryor
    Contributor

    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.

  11. jonpryor commented on May 13, 2026

    @jonpryor
    Contributor

    It also looks like microsoft/cswin32 will emit COM interfaces:

  12. jonpryor commented on May 20, 2026

    @jonpryor
    Contributor

    @jonpryor wrote:

    It also looks like microsoft/cswin32 will emit COM interfaces:

    Just because cswin32 can emit COM interfaces does not mean that it will work for ICoreWebView2:

    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?

    Or this is more evidence that we should just stick with https://github.com/smourier/WebView2Aot.

  13. jonpryor commented on May 28, 2026

    @jonpryor
    Contributor

    PR #23225 was an attempt to update the Uno.UI.Runtime.Skia.Wpf assembly to use smourier/WebView2Aot, and @MartinZikmund noted that:

    WPF target is no longer supported.

    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:

    dotnet publish -c Release -r win-arm64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop `
      -bl Uno.Gallery/Uno.Gallery.csproj -p:SelfContained=true -p:UseSkiaRendering=true `
      -p:IlcGenerateMetadataLog=true -p:IlcGenerateMstatFile=true `
      -p:SkiaPublishAot=true -p:IsAotCompatible=true
    

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

    % ildasm Uno.Gallery/obj/Release/net10.0-desktop/win-arm64/native/Uno.Gallery.mstat -out=refs.il
    % grep '^\.assembly extern.*Skia' refs.il | sort | uniq
    .assembly extern ShimSkiaSharp
    .assembly extern SkiaSharp
    .assembly extern SkiaSharp.SceneGraph
    .assembly extern SkiaSharp.Skottie
    .assembly extern SkiaSharp.Views.Windows
    .assembly extern Svg.Skia
    .assembly extern Uno.Toolkit.Skia.WinUI
    .assembly extern Uno.UI.MediaPlayer.Skia.Win32
    .assembly extern Uno.UI.MediaPlayer.Skia.X11
    .assembly extern Uno.UI.Runtime.Skia
    .assembly extern Uno.UI.Runtime.Skia.Linux.FrameBuffer
    .assembly extern Uno.UI.Runtime.Skia.MacOS
    .assembly extern Uno.UI.Runtime.Skia.Win32
    .assembly extern Uno.UI.Runtime.Skia.Win32.Support
    .assembly extern Uno.UI.Runtime.Skia.X11
    .assembly extern Uno.UI.WebView.Skia.X11

    Indeed, Uno.UI.Runtime.Skia.Wpf is not used.

    Microsoft.Web.WebView2.Core is used:

    % grep -i '^\.assembly extern.*WebView2' refs.il | sort | uniq 
    .assembly extern Microsoft.Web.WebView2.Core

    which is "of course" the problem: Microsoft.Web.WebView2.Core uses "classic" COM Interop, which isn't supported by Native AOT.

    At least I know which assembly needs updating now…

  14. assigned and unassigned on May 28, 2026
  15. jonpryor commented on Jun 8, 2026

    @jonpryor
    Contributor

    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.

  16. khaskoul commented on Jul 31, 2026

    @khaskoul
    Author
    Image

    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

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

Metadata

Metadata

Labels

triage/untriaged

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions