Skip to content

fix(win32): route net10 WebView to WebView2Aot - #23351

Closed
jonpryor with Copilot wants to merge 11 commits into
masterfrom
copilot/fix-webview-component-gallery-app
Closed

jonpryor with Copilot wants to merge 11 commits into
masterfrom
copilot/fix-webview-component-gallery-app

Conversation

Copilot AI commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

PR Type:

🐞 Bugfix

What changed? 🚀

Native AOT on Desktop (net10.0) could fail when opening Gallery WebView and leave the app UI in a broken state. This PR adds a dedicated Win32 AOT WebView path while preserving the existing runtime path for non-AOT targets.

  • Win32 hosting split

    • Added Win32NativeWebViewBase to centralize HWND lifecycle and WndProc behavior (window creation, WM_SIZE/WM_CLOSE/SC_CLOSE forwarding, destruction).
    • Updated Win32NativeWebView to inherit from the base and keep non-AOT mswebview2 logic local.
  • Native AOT WebView implementation

    • Added Win32NativeAotWebView (for NET10_0_OR_GREATER) using WebView2Aot for environment/controller creation.
    • Bridges created COM WebView object into Uno’s existing CoreWebView2 event/navigation flow to keep behavior consistent (navigation, history, title, script execution, resource filters, virtual host mapping).
  • Provider routing

    • Win32NativeWebViewProvider.CreateNativeWebView() now selects:
      • Win32NativeAotWebView on NET10_0_OR_GREATER
      • Win32NativeWebView otherwise
  • Packaging / targeting

    • Added conditional WebView2Aot package reference in Uno.UI.Runtime.Skia.Win32.csproj with:
      • $([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net10.0'))
    • Added centralized version pin for WebView2Aot in src/Directory.Build.targets.
#if NET10_0_OR_GREATER
return new Win32NativeAotWebView(owner, contentPresenter);
#else
return new Win32NativeWebView(owner, contentPresenter);
#endif

PR Checklist ✅

Copilot AI review requested due to automatic review settings May 28, 2026 14:30
Copilot AI self-assigned this May 28, 2026
Copilot AI removed the request for review from Copilot May 28, 2026 14:30
Copilot AI requested review from Copilot and removed request for Copilot May 28, 2026 15:05
@CLAassistant

CLAassistant commented May 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ jonpryor
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI requested review from Copilot and removed request for Copilot May 28, 2026 15:12
Copilot AI changed the title [WIP] Fix webview not loading in Gallery app with native AOT enabled fix(win32): route net10 WebView to WebView2Aot May 28, 2026
Copilot AI requested a review from jonpryor May 28, 2026 15:13
Copilot AI review requested due to automatic review settings June 5, 2026 20:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Win32 Skia Gallery WebView failures under .NET 10 NativeAOT by introducing a dedicated WebView2Aot-based implementation and routing the Win32 WebView provider to use it on NET10_0_OR_GREATER, while keeping the existing Microsoft.Web.WebView2 runtime path for earlier TFMs.

Changes:

  • Added Win32NativeWebViewBase to centralize HWND creation, WndProc handling, sizing/close forwarding, and destruction.
  • Added Win32NativeAotWebView (NET10+) using WebView2Aot COM APIs and wrapper types to preserve existing CoreWebView2 behavior.
  • Added conditional WebView2Aot package reference for net10.0 and pinned its version centrally.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Uno.UI.Runtime.Skia.Win32/Uno.UI.Runtime.Skia.Win32.csproj Adds conditional WebView2Aot reference for net10 builds.
src/Uno.UI.Runtime.Skia.Win32/UI/Xaml/Controls/WebView/Win32NativeWebViewBase.cs Introduces shared Win32 child window lifecycle + WndProc forwarding for WebView hosting.
src/Uno.UI.Runtime.Skia.Win32/UI/Xaml/Controls/WebView/Win32NativeWebView.cs Routes NET10 to AOT implementation; refactors existing WebView2 runtime implementation to inherit from the shared base.
src/Uno.UI.Runtime.Skia.Win32/UI/Xaml/Controls/WebView/Win32NativeAotWebView.cs Adds the NativeAOT WebView2Aot-backed implementation and WebResourceRequested wrapper types.
src/Directory.Build.targets Pins WebView2Aot package version centrally.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

@kazo0

kazo0 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI and others added 8 commits June 24, 2026 14:01
Claude output of:

> Update `src/Uno.UI.Runtime.Skia.Win32/UI/Xaml/Controls/WebView/Win32NativeAotWebView.cs`
> so that it does not mention `Microsoft.Web.WebView2.Core` or the `mswebview2` extern alias.
> All functionality within this file should use only the WebView2Aot NuGet package.
Stop ignoring IDE0055 and address all IDE0055 warnings.
Context: smourier/DirectNAot#9

`DirectN.PWSTR.From(string)` may interact poorly with the GC; see
smourier/DirectNAot#9 for details.

Instead of using `PWSTR.From(string)`, use `new PWSTR(char*)`.

Update `Uno.UI.Runtime.Skia.Win32.csproj` to use the
[Microsoft.CodeAnalysis.BannedApiAnalyzers][0] NuGet package to "ban"
use of `PWSTR.From(string)`.

[0]: https://www.nuget.org/packages/Microsoft.CodeAnalysis.BannedApiAnalyzers/
@jonpryor
jonpryor force-pushed the copilot/fix-webview-component-gallery-app branch from 7cab432 to 5dfd6fd Compare June 24, 2026 18:05
Copilot AI review requested due to automatic review settings June 24, 2026 18:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Comment on lines 27 to +30
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Aliases="mswebview2" PrivateAssets="all" />
<PackageReference Include="WebView2Aot" Condition="$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net10.0'))" />

Comment on lines +104 to +116
Presenter.DispatcherQueue.TryEnqueue(() =>
{
var success = PInvoke.DestroyWindow(Hwnd);
if (!success && this.Log().IsEnabled(LogLevel.Error))
{
this.Log().Error($"{nameof(PInvoke.DestroyWindow)} failed: {Win32Helper.GetErrorMessage()}");
}

lock (_hwndToWebView)
{
_hwndToWebView.Remove(Hwnd);
}
});
Comment on lines 229 to 233
_coreWebView.RaiseNewWindowRequested(
e.Uri,
CoreWebView2.BlankUri,
out var handled);
e.Uri,
CoreWebView2.BlankUri,
out var handled);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 802e616.

jonpryor added 2 commits June 24, 2026 14:21
Remove unnecessary whitespace changes.

Add support for `AllowSingleSignOnUsingOSPrimaryAccount` to
`Win32NativeAotWebView`, consistent with `Win32NativeWebView`.
Copilot AI review requested due to automatic review settings June 25, 2026 13:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment on lines +88 to +89
controller.get_CoreWebView2(out var coreWebView).ThrowOnError();
tcs.TrySetResult((controller, (WebView2.ICoreWebView2_22)coreWebView));
Comment on lines +406 to +407
_nativeWebView.get_Environment(out var environment).ThrowOnError();
var env2 = (WebView2.ICoreWebView2Environment2)environment;
Comment on lines +423 to +428
env2.CreateWebResourceRequest(
new PWSTR(p_requestUri),
new PWSTR(p_requestMethod),
bodyIStream!,
new PWSTR(p_requestHeaders),
out var request).ThrowOnError();
@jonpryor

Copy link
Copy Markdown
Contributor

Superseded by #23604.

@jonpryor jonpryor closed this Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

6 participants