Welcome Guest Search | Active Topics | Sign In | Register

This WebView either has already been destroyed or is being destroyed. Options
Stefan Koell
Posted: Monday, February 27, 2023 2:20:44 AM
Rank: Advanced Member
Groups: Member

Joined: 12/23/2013
Posts: 114
Hi,

I have a strange issue and was hoping you can help me. I regularly get crash reports from my users where no crash repost should happen. The exception and stack trace is the following:

This WebView either has already been destroyed or is being destroyed.
Code: C#
at EO.Base.Runtime.dbcp(Object lsy, Exception lsz, Boolean lta)
at EO.WebBrowser.WebView.fiyz(Boolean fq)
at EO.WebBrowser.WebView.LoadUrl(String url, Boolean skipCache)
at EO.WebBrowser.WebView.LoadUrl(String url)
at EO.WebBrowser.WebView.set_Url(String value)
at lwhihg.lwgpsl(Object, String)
at gyrkh.<>c__DisplayClass136_0.<NavigateSafe>b__0() in <9pbU/0LjpCexFwUaxM2copsqI6CCCN0x+6Hd3IhFJU1JsDLkQnLDomz/TIZwbEZbST0gl2A7fS233q/rVcuvqE1ML7Xp3gL0ZdvYswqafziGwoDmS1vm+jAAIfrgdMcDp8qkboLY9uAFnruX7YurnchD132uk2JAzpzHT4fghR8=>:line 787
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()


Code: C#
private void NavigateSafe(string url)
    {
        try
        {
            this.BeginInvokeEx(() =>
            {
                if (WebControl != null) 
                    WebControl.WebView.Url = url;                                 <-- this is Line 787
            });
        }
        catch (Exception exception)
        {
            Logger.LogWarning(exception, "Navigate('{Url}') failed", url);
        }
    }


The line which is causing the exception is within a try/catch block. So I'm not sure why this happens or how I can prevent the user from gettin a crash.

Any idea why this happens?

Thanks,
Stefan
eo_support
Posted: Monday, February 27, 2023 11:11:20 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

When you use BeginInvoke with a lambda expression, the body of that expression is compiled into a separate function and it is being called at a later time --- which is the entire point of BeginInvoke.

Before that function is being called at a later time, your try catch block in the original function does NOT catch the exception of the later call. It only catch the exception when BeginInvoke is called. If you want to catch the exception inside the body of the lambda expression, you have to put try catch inside the body.

Thanks
Stefan Koell
Posted: Tuesday, February 28, 2023 1:35:36 AM
Rank: Advanced Member
Groups: Member

Joined: 12/23/2013
Posts: 114
This makes sense! Will put the try/catch inside the lambda. Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.