Problem
A WPF Blazor Hybrid app that opens a message box using System.Windows.Forms.MessageBox.Show
crashes after a couple of seconds. Same happens when opening a modal form.
It crashes only when running WITH the Visual Studio debugger. When run without debugging it does NOT crash.
Visual Studio Debug Output
The following appears in the Visual Studio debug output:
'WpfBlazorHybridMessageBoxTest.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Windows.Forms.dll'. Symbols loaded.'WpfBlazorHybridMessageBoxTest.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Windows.Forms.Primitives.dll'. The thread '.NET TP Worker' (25888) has exited with code 0 (0x0).The thread '.NET TP Worker' (45744) has exited with code 0 (0x0).The thread '.NET TP Worker' (57576) has exited with code 0 (0x0).The thread '.NET TP Worker' (22500) has exited with code 0 (0x0).The program '[24472] WpfBlazorHybridMessageBoxTest.exe: Program Trace' has exited with code 0 (0x0).The program '[24472] WpfBlazorHybridMessageBoxTest.exe' has exited with code 2147483651 (0x80000003).Exit code 0x80000003 seems to be related to breakpoints, but I'm not sure.
Event Viewer
The following appears in the Event Viewer:
Faulting application name: WpfBlazorHybridMessageBoxTest.exe, version: 1.0.0.0, time stamp: 0x66960000Faulting module name: EmbeddedBrowserWebView.dll, version: 129.0.2792.65, time stamp: 0x66f49609Exception code: 0x80000003Fault offset: 0x00000000003a84fdFaulting process id: 0x0x5F98Faulting application start time: 0x0x1DB141109AE3F08Faulting application path: F:\Test\WpfBlazorHybridMessageBoxTest\bin\Debug\net8.0-windows\WpfBlazorHybridMessageBoxTest.exeFaulting module path: C:\Program Files (x86)\Microsoft\EdgeWebView\Application\129.0.2792.65\EBWebView\x64\EmbeddedBrowserWebView.dllReport Id: bddefc72-2dec-40a6-8240-aebac0069299Faulting package full name: Faulting package-relative application ID: There are also two Windows Error Reporting entries.
How to reproduce?
- Create a WPF Blazor Hybrid app with the steps described in this tutorial:
https://learn.microsoft.com/en-us/aspnet/core/blazor/hybrid/tutorials/wpf?view=aspnetcore-8.0 - Add support for Windows Forms by adding this property to the '.csproj'-file:
<UseWindowsForms>true</UseWindowsForms> - Resolve ambiguity of
ApplicationinApp.xaml.cs, by explicitly specifying the namespace:public partial class App : System.Windows.Application - Add the message box call to
Counter.razor:
{ currentCount++; System.Windows.Forms.MessageBox.Show("Counter increased");}- Show a form from
Counter.razor:
{ currentCount++; var f = new System.Windows.Forms.Form(); f.ShowDialog();}Why use Windows Forms inside a Blazor Hybrid application?
We do have a very large application that:
- runs on .NET Framework 4.7.2
- is a WPF application
- uses the Internet Explorer browser control to render its UI
- has all browser event handling, client-side logic, etc, running in .NET Framework.So it's a blend of IE and .NET Framework. Very similar to Blazor Hybrid, but developed many years ago by ourselves.
We're looking into the migration to Blazor Hybrid. Changing all existing existing MessageBox calls and other (third party) modal forms is a major effort. We want to keep it untouched.