Skip to content

Commit

Permalink
Avoid ObjectDisposedException when host got disposed (#5003)
Browse files Browse the repository at this point in the history
  • Loading branch information
campersau authored and amaitland committed Dec 22, 2024
1 parent bc5f795 commit 0b8761c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,21 @@ private void InitialLoad(bool? isLoading, CefErrorCode? errorCode)

initialLoadAction = null;

var host = browser?.GetHost();
int statusCode = 0;

var navEntry = host?.GetVisibleNavigationEntry();
try
{
var host = browser?.GetHost();

var navEntry = host?.GetVisibleNavigationEntry();

int statusCode = navEntry?.HttpStatusCode ?? -1;
statusCode = navEntry?.HttpStatusCode ?? -1;
}
catch (ObjectDisposedException)
{
// The host might got disposed
// https://github.com/cefsharp/CefSharp/issues/5002
}

//By default 0 is some sort of error, we map that to -1
//so that it's clearer that something failed.
Expand Down

0 comments on commit 0b8761c

Please sign in to comment.