Skip to content

Commit 0b8761c

Browse files
campersauamaitland
authored andcommitted
Avoid ObjectDisposedException when host got disposed (#5003)
1 parent bc5f795 commit 0b8761c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,21 @@ private void InitialLoad(bool? isLoading, CefErrorCode? errorCode)
449449

450450
initialLoadAction = null;
451451

452-
var host = browser?.GetHost();
452+
int statusCode = 0;
453453

454-
var navEntry = host?.GetVisibleNavigationEntry();
454+
try
455+
{
456+
var host = browser?.GetHost();
457+
458+
var navEntry = host?.GetVisibleNavigationEntry();
455459

456-
int statusCode = navEntry?.HttpStatusCode ?? -1;
460+
statusCode = navEntry?.HttpStatusCode ?? -1;
461+
}
462+
catch (ObjectDisposedException)
463+
{
464+
// The host might got disposed
465+
// https://github.com/cefsharp/CefSharp/issues/5002
466+
}
457467

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

0 commit comments

Comments
 (0)