Skip to content

Add .NET 8 (coreclr) compatibility for Windows ARM64#1803

Open
smparkes wants to merge 1 commit intor0x0r:masterfrom
smparkes:fix/dotnet8-coreclr
Open

Add .NET 8 (coreclr) compatibility for Windows ARM64#1803
smparkes wants to merge 1 commit intor0x0r:masterfrom
smparkes:fix/dotnet8-coreclr

Conversation

@smparkes
Copy link
Copy Markdown
Contributor

pywebview fails to load on Windows ARM64 because pythonnet's .NET Framework (netfx) runtime is not available on ARM64 — the clr-loader dependency chain (NXPorts → dnlib) does not support ARM64: pythonnet/pythonnet#2523

The upstream fallback in #1791 successfully switches to coreclr when netfx is unavailable, but pywebview then fails because several components assume .NET Framework.

Use FolderBrowserDialog for the folder picker on coreclr, since the internal FileDialogNative types (IFileDialog, FOS_PICKFOLDERS) used by the existing OpenFolderDialog don't exist in .NET 8. On .NET Framework, the existing FileDialogNative reflection code is preserved unchanged, including its support for multiple folder selection. FolderBrowserDialog does not support multi-select; this limitation only affects coreclr users. (.NET 9 adds FolderBrowserDialog.Multiselect which could be used in a future update.) The netfx code is wrapped in an if/else on PYTHONNET_RUNTIME, which adds indentation; ignoring whitespace (https://github.com/r0x0r/pywebview/compare/master...smparkes:fix/dotnet8-coreclr?expand=1&w=1) makes the diff much simpler to review.

Update bundled WebView2 interop DLLs from Microsoft.Web.WebView2 NuGet package 1.0.2957.106 to 1.0.3240.44 (netcoreapp3.0 target): https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.3240.44 The old DLLs referenced System.Windows.Forms.ContextMenu, which was removed in .NET 6+:
https://learn.microsoft.com/en-us/dotnet/core/compatibility/windows-forms/6.0/apis-throw-argumentnullexception The new DLLs use ContextMenuStrip instead, which exists on both .NET Framework and .NET 8, so this change is safe for all platforms.

Skip the .NET Framework registry check in _is_chromium() when running on coreclr, since coreclr does not register in the .NET Framework registry (HKLM...\NDP\v4\Full). Also fix a potential UnboundLocalError by initializing net_key before the try block and guarding CloseKey.

Add explicit clr.AddReference('Microsoft.Win32.SystemEvents') when PYTHONNET_RUNTIME=coreclr. This assembly is auto-loaded on .NET Framework but requires an explicit reference on coreclr.

pywebview fails to load on Windows ARM64 because pythonnet's .NET
Framework (netfx) runtime is not available on ARM64 — the clr-loader
dependency chain (NXPorts → dnlib) does not support ARM64:
pythonnet/pythonnet#2523

The upstream fallback in r0x0r#1791 successfully switches to coreclr when
netfx is unavailable, but pywebview then fails because several
components assume .NET Framework.

Use FolderBrowserDialog for the folder picker on coreclr, since the
internal FileDialogNative types (IFileDialog, FOS_PICKFOLDERS) used
by the existing OpenFolderDialog don't exist in .NET 8. On .NET
Framework, the existing FileDialogNative reflection code is preserved
unchanged, including its support for multiple folder selection.
FolderBrowserDialog does not support multi-select; this limitation
only affects coreclr users. (.NET 9 adds FolderBrowserDialog.Multiselect
which could be used in a future update.) The netfx code is wrapped in
an if/else on PYTHONNET_RUNTIME, which adds indentation; ignoring
whitespace (https://github.com/r0x0r/pywebview/compare/master...smparkes:fix/dotnet8-coreclr?expand=1&w=1)
makes the diff much simpler to review.

Update bundled WebView2 interop DLLs from Microsoft.Web.WebView2
NuGet package 1.0.2957.106 to 1.0.3240.44 (netcoreapp3.0 target):
https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.3240.44
The old DLLs referenced System.Windows.Forms.ContextMenu, which was
removed in .NET 6+:
https://learn.microsoft.com/en-us/dotnet/core/compatibility/windows-forms/6.0/apis-throw-argumentnullexception
The new DLLs use ContextMenuStrip instead, which exists on both .NET
Framework and .NET 8, so this change is safe for all platforms.

Skip the .NET Framework registry check in _is_chromium() when running
on coreclr, since coreclr does not register in the .NET Framework
registry (HKLM\...\NDP\v4\Full). Also fix a potential UnboundLocalError
by initializing net_key before the try block and guarding CloseKey.

Add explicit clr.AddReference('Microsoft.Win32.SystemEvents') when
PYTHONNET_RUNTIME=coreclr. This assembly is auto-loaded on .NET
Framework but requires an explicit reference on coreclr.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@smparkes smparkes force-pushed the fix/dotnet8-coreclr branch from 61181ac to a2bf0df Compare April 2, 2026 23:05
@r0x0r
Copy link
Copy Markdown
Owner

r0x0r commented Apr 10, 2026

I tried running it, but I get this exception out of the box.

[pywebview] pythonnet cannot be loaded
Traceback (most recent call last):
  File "\\mac\Home\Code\pywebview\webview\guilib.py", line 74, in import_winforms
    import webview.platforms.winforms as guilib
  File "\\mac\Home\Code\pywebview\webview\platforms\winforms.py", line 146, in <module>
    from . import edgechromium as Chromium
  File "\\mac\Home\Code\pywebview\webview\platforms\edgechromium.py", line 48, in <module>
    from Microsoft.Web.WebView2.WinForms import CoreWebView2CreationProperties, WebView2  # noqa: E402
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'Microsoft.Web.WebView2.WinForms'  

dotnet --info is as follows

.NET SDK:
 Version:           10.0.201
 Commit:            4d3023de60
 Workload version:  10.0.200-manifests.0793c108
 MSBuild version:   18.3.0-release-26153-122+4d3023de6

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26200
 OS Platform: Windows
 RID:         win-arm64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.201\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
  Version:      10.0.5
  Architecture: arm64
  Commit:       a612c2a105

.NET SDKs installed:
  10.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@smparkes
Copy link
Copy Markdown
Contributor Author

Looking

I tried running it, but I get this exception out of the box.

[pywebview] pythonnet cannot be loaded
Traceback (most recent call last):
  File "\\mac\Home\Code\pywebview\webview\guilib.py", line 74, in import_winforms
    import webview.platforms.winforms as guilib
  File "\\mac\Home\Code\pywebview\webview\platforms\winforms.py", line 146, in <module>
    from . import edgechromium as Chromium
  File "\\mac\Home\Code\pywebview\webview\platforms\edgechromium.py", line 48, in <module>
    from Microsoft.Web.WebView2.WinForms import CoreWebView2CreationProperties, WebView2  # noqa: E402
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'Microsoft.Web.WebView2.WinForms'  

dotnet --info is as follows

.NET SDK:
 Version:           10.0.201
 Commit:            4d3023de60
 Workload version:  10.0.200-manifests.0793c108
 MSBuild version:   18.3.0-release-26153-122+4d3023de6

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26200
 OS Platform: Windows
 RID:         win-arm64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.201\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
  Version:      10.0.5
  Architecture: arm64
  Commit:       a612c2a105

.NET SDKs installed:
  10.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@smparkes
Copy link
Copy Markdown
Contributor Author

Hmmm ... not sure just yet.
But a meta-question: how do you want to approach this? There's a big question whether to go full coreclr (this does; or did ...) or keep netfx for intel and only use coreclr for arm, at least for now.
I think we can provide both dlls and select based on arch at run time.
That would avoid people having to get a new .net for intel arch.
LMKWYT

@r0x0r
Copy link
Copy Markdown
Owner

r0x0r commented Apr 16, 2026

My take is that it makes sense to target coreclr by default and fall back to netfx. Not sure how dramatic change this is, but maybe this can be released in the next major version.

BTW I have already updated webview2 dlls in the current master.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants