cefsharp/CefSharp · critical · InvalidOperationException

Cef.IsInitialized was false!.Check the log file for errors!.

Error message

Cef.IsInitialized was false!.Check the log file for errors!. See https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting#log-file for details.

What it means

Thrown by InitializeCefInternal when Cef.IsInitialized is explicitly false (not null). This means CEF was initialized at some point and is no longer initialized, typically because Cef.Shutdown() was already called. Re-initializing CEF after shutdown is not supported, so the boolean false is treated as a hard failure.

Source

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

            ResourceRequestHandlerFactory = null;
            RenderProcessMessageHandler = null;

            this.FreeDevToolsContext();
        }

        private static void InitializeCefInternal()
        {
            if (Cef.IsInitialized == null)
            {
                if (!Cef.Initialize(new CefSettings()))
                {
                    throw new InvalidOperationException(CefInitializeFailedErrorMessage);
                }
            }

            if (Cef.IsInitialized == false)
            {
                throw new InvalidOperationException(CefIsInitializedFalseErrorMessage);
            }
        }

        /// <summary>
        /// Check is browser is initialized
        /// </summary>
        /// <returns>true if browser is initialized</returns>
        private bool InternalIsBrowserInitialized()
        {
            // Use CompareExchange to read the current value - if disposeCount is 1, we set it to 1, effectively a no-op
            // Volatile.Read would likely use a memory barrier which I believe is unnecessary in this scenario
            return Interlocked.CompareExchange(ref browserInitialized, 0, 0) == 1;
        }

        /// <summary>
        /// Throw exception if browser not initialized.
        /// </summary>
        /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception>

View on GitHub (pinned to 16bc6e0711)

Solutions

  1. Do not create ChromiumWebBrowser instances after Cef.Shutdown(); keep a single CEF lifecycle for the process.
  2. Fix shutdown ordering so all browsers are disposed before Cef.Shutdown().
  3. For restart scenarios, run CEF in a separate process you can relaunch instead of re-initializing in-process.
  4. Guard browser creation with a check that Cef.IsInitialized is not false before constructing.

Example fix

// before
Cef.Shutdown();
var b = new ChromiumWebBrowser(url); // IsInitialized now false -> throws

// after
// keep CEF alive for the whole process; dispose all browsers, then call Shutdown only once at app exit.
Defensive patterns

Strategy: validation

Validate before calling

if (Cef.IsInitialized == false)
    throw new InvalidOperationException("CEF has been shut down; cannot create a new browser in this process.");
// Only construct browsers while CEF is alive:
var browser = new ChromiumWebBrowser(url);

Try / catch

try { var browser = new ChromiumWebBrowser(url); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Cef.IsInitialized was false"))
{ /* do not retry; CEF must be restarted in a fresh process */ }

Prevention

When it happens

Trigger: Calling code that constructs a ChromiumWebBrowser (which triggers InitializeCefInternal) after Cef.Shutdown() has run; app shutdown ordering issues where a browser is created during teardown; a second CEF lifecycle in the same process.

Common situations: Hot-reload/restart logic that shuts CEF down and tries to bring it back; disposal ordering where a late-created browser references a shut-down CEF; test runner reusing a process across fixtures that call Shutdown.

Related errors


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