MicrosoftEdge / MicrosoftEdge/WebView2Feedback

WPF application crashes when disposing WebView2 from within window's closing handler

Open
#3,792 1 comment 0 reactions 1 assignee View on GitHub

@vbryh-msft is already working on this.

Since Sep 18, 2023.

bug
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Description
When a WebView2 window closes, we've found that we must explicitly dispose WebView2 by disposing the control, otherwise WebView2 processes are left running even after the window has been closed.

We do this within window's Closing event handler. This is fine normally, but when there is a process error, something appears to go very wrong and our WPF application crashes.

As per the discussion here https://github.com/MicrosoftEdge/WebView2Feedback/issues/3225, I haven't been able to replicate WebView2 crashing in a way which causes this. I've tried killing different WebView2 processes, and forcing an out of memory exception. But nothing reproduces this issue. This issue is seen every time there is a process failure on our user's machines. We're currently handling all Process Failures the same - in every case we close the window.

I have a hunch that we're disposing WebView2 incorrectly, as it's at this point that logs stop. I was thinking I would trial and error how we're disposing WebView2 by doing so from within the Process Failed handler itself, but before doing so wondered if anyone has any wisdom they can share here.

How does the WebView2 team suggest to safely dispose of WebView2 processes in the event of a process failure?

Thank you!

Version
SDK: 1.0.1518.46
Runtime: 116.0.1938.76
Framework: WPF
OS: Windows 10

Regression
No

Repro Steps
Can't reproduce, as it hasn't been possible to reproduce process failures which cause this to happen

This appears to happen on many different versions of WebView2, the information shared below is just the latest.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.