Add .NET 8 (coreclr) compatibility for Windows ARM64#1803
Add .NET 8 (coreclr) compatibility for Windows ARM64#1803smparkes wants to merge 1 commit intor0x0r:masterfrom
Conversation
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>
61181ac to
a2bf0df
Compare
|
I tried running it, but I get this exception out of the box.
|
|
Looking
|
|
Hmmm ... not sure just yet. |
|
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. |
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.