cefsharp/CefSharp · warning · InvalidOperationException
Unexpected failure of calling CEF->GetZoomLevelAsync
Error message
Unexpected failure of calling CEF->GetZoomLevelAsync
What it means
Identical to the WPF version: after the HwndHost-based browser initializes, CefSharp calls GetZoomLevelAsync to sync the zoom level. If that task faults (browser disposed mid-call, CEF internal error), the continuation throws InvalidOperationException wrapping the original exception as InnerException.
Source
Thrown at CefSharp.Wpf/HwndHost/ChromiumWebBrowser.cs:1308
{
if (newValue && !IsDisposed)
{
var task = this.GetZoomLevelAsync();
task.ContinueWith(previous =>
{
if (previous.Status == TaskStatus.RanToCompletion)
{
UiThreadRunAsync(() =>
{
if (!IsDisposed)
{
SetCurrentValue(ZoomLevelProperty, previous.Result);
}
});
}
else
{
throw new InvalidOperationException("Unexpected failure of calling CEF->GetZoomLevelAsync", previous.Exception);
}
}, TaskContinuationOptions.ExecuteSynchronously);
}
}
/// <summary>
/// The title of the web page being currently displayed.
/// </summary>
/// <value>The title.</value>
/// <remarks>This property is implemented as a Dependency Property and fully supports data binding.</remarks>
public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}
/// <summary>
/// The title propertyView on GitHub (pinned to 16bc6e0711)
Solutions
- Subscribe to TaskScheduler.UnobservedTaskException at startup to observe and log without crashing.
- Prevent premature disposal — ensure the HwndHost browser is not torn down during the init-completion window.
- Inspect the InnerException (previous.Exception) to find the underlying CEF fault.
- Upgrade CefSharp to a version with init/dispose race fixes.
Example fix
// after — observe at startup
TaskScheduler.UnobservedTaskException += (s, e) =>
{
Log.Warn("Unobserved CEF task fault", e.Exception?.InnerException ?? e.Exception);
e.SetObserved();
}; Defensive patterns
Strategy: try-catch
Validate before calling
// No pre-call validation possible — internal library continuation.
// Observe globally:
TaskScheduler.UnobservedTaskException += (s, e) =>
{
if (e.Exception?.Message?.Contains("GetZoomLevelAsync") == true)
{
Log.Warn("HwndHost CEF zoom sync faulted", e.Exception.InnerException);
e.SetObserved();
}
}; Try / catch
// Cannot catch at call site — thrown in library-internal continuation.
// Only surface: TaskScheduler.UnobservedTaskException
TaskScheduler.UnobservedTaskException += (s, e) =>
{
e.SetObserved();
}; Prevention
- Do not dispose the HwndHost browser during the init-to-zoom-sync window.
- Always handle TaskScheduler.UnobservedTaskException when using CefSharp.
- Upgrade CefSharp to benefit from init/dispose race fixes.
When it happens
Trigger: Fires inside OnIsBrowserInitializedChanged (HwndHost variant) when the GetZoomLevelAsync continuation sees a non-RanToCompletion status. The throw is in an ExecuteSynchronously continuation and surfaces as an unobserved task exception.
Common situations: HwndHost browser being disposed during or right after initialization. CEF crash during init. Race between init completion and shutdown.
Related errors
- Unexpected failure of calling CEF->GetZoomLevelAsync
- Browser has already been created. BrowserSettings must be se
- Browser has already been created. RequestContext must be set
- Cef.IsInitialized was false!.Check the log file for errors!.
- The ChromiumWebBrowser instance creates the underlying Chrom
AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13).
Data as JSON: /api/errors/e787c93b349a7d17.
Report an issue: GitHub.