diff --git a/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs b/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs index fe974d9a6..8458eebc8 100644 --- a/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs +++ b/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs @@ -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.