Skip to content

Commit 4757ee6

Browse files
authored
Avoid ObjectDisposedException when host got disposed (#5003)
1 parent 26995e7 commit 4757ee6

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs

Lines changed: 13 additions & 3 deletions
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)