-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When destroyed, the error "source property cannot be set to null" is thrown #3725
Comments
I've already either commented about this or started an issue. Whomever wrote the wpf code even coded it to throw an error if the source is null meaning you need special work arounds if you put wv2 in a wpf tabcontrol. Edit: it's actually tracked #1136 |
My apologies for lodging a duplicate complaint. I remember seeing this issue had been reported, but for some reason couldn't find it again. I'm new to GitHub (this was my first bug report); should I delete this one, or add to the list of "me too" folks for issue #1136? Not that my voice will have any effect, given the bug report is 2.5 years old. I tried the "TargetNullValue=about:blank, FallbackValue=about:blank" mentioned in one of the comments... this seems to do the trick. I do now get a warning about the control being "already initialized with a different CoreWebView2Environment"... but hopefully I can figure this one out. Thank you, darbid. |
Pretty sure the MS team like closed issues 😂😂. But be sure to comment on the tracked bug to add support. The other way is to tracked data context changes in code behind. |
By the way and I'm far from an expert but if you have properly disposed of mv2 by calling dispose you should not have the problem. Also as you noted MVVM, make sure you bind the source to a property that is never null too. |
I too am no expert at WPF. When it works it's very cool. When it doesn't, I want to jump off a cliff... and I end up face-rolling suggestions I find online. I'm not creating the webview2 in the code-behind, so it isn't clear how I'd explicitly dispose of the control. I did implement code to dispose of the control which contains the wv2... this didn't help. |
I was able to find a workaround for my issue. In my user control I hook the DataContextChanged event. In the handler method, if the data context has been set to null, I set the WebView2 page source to "about:blank". |
I was able to find a workaround, and this is a duplicate of #1136, so I'm closing this incident. |
I have implemented a WPF application which hosts an instance of WebView2. When I close the hosting window and the control is destroyed, the Source property is set to null, an error is thrown, and garbage is left onscreen (see attached image). I have searched for a solution; all I have found is others reporting the same behavior... but no solutions. My instructions are to make this work in a production application, yet this behavior precludes using this control.
Version
Runtime: 1.0.1901.177
Framework: WPF, MVVM, x64
OS: Win10
Regression
This is the only version of the control which I have tested.
Repro Steps
Host a WebView2 in a user control, then close the window hosting that control.
The text was updated successfully, but these errors were encountered: