cefsharp/CefSharp · error · ObjectDisposedException

ChromiumWebBrowser

Error message

ChromiumWebBrowser

What it means

Thrown by ThrowExceptionIfDisposed as a standard ObjectDisposedException when the ChromiumWebBrowser has already been disposed (IsDisposed is true). The 'ChromiumWebBrowser' string is the object name passed to ObjectDisposedException. Any member guarded by ThrowExceptionIfDisposed will raise this after Dispose().

Source

Thrown at CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs:567

        /// </summary>
        /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception>
        private void ThrowExceptionIfBrowserNotInitialized()
        {
            if (!InternalIsBrowserInitialized())
            {
                throw new Exception(BrowserNotInitializedExceptionErrorMessage);
            }
        }

        /// <summary>
        /// Throw exception if disposed.
        /// </summary>
        /// <exception cref="ObjectDisposedException">Thrown when a supplied object has been disposed.</exception>
        private void ThrowExceptionIfDisposed()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException("ChromiumWebBrowser");
            }
        }

        private int GetChromiumChildProcessId(string frameIdentifier)
        {
            try
            {
                var parts = frameIdentifier.Split('-');

                if (int.TryParse(parts[0], out var childProcessId))
                    return childProcessId;
            }
            catch
            {

            }

            return -1;

View on GitHub (pinned to 16bc6e0711)

Solutions

  1. Check IsDisposed before using the browser in callbacks.
  2. Stop/await outstanding async operations before disposing.
  3. Remove event handlers before disposal to avoid late invocations.
  4. Scope references so nothing outlives the browser lifecycle.

Example fix

// before
browser.Load(url); // may run after Dispose in a callback

// after
if (!browser.IsDisposed)
{
    browser.Load(url);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!browser.IsDisposed) { browser.Load(url); }

Type guard

static bool IsUsable(ChromiumWebBrowser b) => b != null && !b.IsDisposed;

Try / catch

try { browser.Load(url); }
catch (ObjectDisposedException) { /* browser already disposed; ignore or recreate */ }

Prevention

When it happens

Trigger: Calling a method/property on the browser after Dispose() has run; using a browser held by a using-block or disposed parent; racing with disposal in an async callback.

Common situations: DI container disposing the browser while a callback still references it; window close disposing the control and a late event handler firing; OffScreen browser used after explicit dispose.

Related errors


AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13). Data as JSON: /api/errors/470846714df1d04b. Report an issue: GitHub.