If a WPF dialog is loaded in a background thread, and disposable components are not manually disposed, app crashes
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
This issue appears to be a regression in .net 8 WPF. I've linked a minimal repro project that duplicates the issue we're seeing. App does the following:
- Main window loads
- Button on main window launches a dialog in a background thread
- Dialog has a webview2 control
Closing the dialog without manually disposing the webview2 crashes the application. If you click the "close me" button I added to the dialog, it disposes the webview2, and the crash doesn't happen.
Switching the runtime from .net 8 to .net 7 fixes the issue. You can close without disposing the controls.
### Reproduction Steps
Minimal repro project showing the issue:
[WPFDialogTest.zip](https://github.com/dotnet/wpf/files/14605395/WPFDialogTest.zip)
### Expected behavior
App should not throw an exception that terminates in an Environment.FailFast
### Actual behavior
App throws an exception if WebView2 is not manually disposed:
System.ExecutionEngineException
HResult=0x80131506
Message=Exception of type 'System.ExecutionEngineException' was thrown.
An unhandled exception of type 'System.ExecutionEngineException' occurred in System.Private.CoreLib.dl
### Regression?
Yes, working in .net 6 and .net 7
### Known Workarounds
Manually disposing webview2 fixes issue.
### Impact
Crash is reproducible in prod, and was blocking upgrade from .net 6 to .net 8 until we found the workaround.
### Configuration
.net 8.0.202, win11 22635.3286, x64
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.