cefsharp/CefSharp · error · InvalidOperationException
CookieManager store is not initialized.
Error message
CookieManager store is not initialized.
What it means
Thrown by ICookieManager.DeleteCookies on CookieManagerDecorator when the underlying cookie store is not yet ready (managerReady is false). The decorator defers all cookie operations until the CEF store initialization Task completes; calling DeleteCookies before that point throws InvalidOperationException because there is no initialized store to delete from.
Source
Thrown at CefSharp/Internals/CookieManagerDecorator.cs:58
{
managerReady = x.Result;
});
}
}
bool ICookieManager.IsDisposed
{
get { return manager.IsDisposed; }
}
bool ICookieManager.DeleteCookies(string url, string name, IDeleteCookiesCallback callback)
{
if (managerReady)
{
return manager.DeleteCookies(url, name, callback);
}
throw new InvalidOperationException(NotInitialziedExceptionMsg);
}
void IDisposable.Dispose()
{
manager.Dispose();
}
bool ICookieManager.FlushStore(ICompletionCallback callback)
{
if (managerReady)
{
return manager.FlushStore(callback);
}
throw new InvalidOperationException(NotInitialziedExceptionMsg);
}
bool ICookieManager.SetCookie(string url, Cookie cookie, ISetCookieCallback callback)View on GitHub (pinned to 16bc6e0711)
Solutions
- Await store readiness before issuing cookie calls: obtain the manager and wait for its initialization before DeleteCookies.
- Use Cef.GetGlobalCookieManager() which is ready after Cef.Initialize, for app-global cookies.
- Retry on the InvalidOperationException or defer the call to a browser/context initialized callback.
- In tests, wait until the browser/context IsBrowserInitialized/initialized event fires before touching cookies.
Example fix
// before (races store init)
var cm = requestContext.GetCookieManager(null);
await cm.DeleteCookiesAsync("https://example.com", "session");
// after (wait for readiness)
var cm = requestContext.GetCookieManager(null);
// await the store init task / context initialization first
await waitForContextInitTask;
await cm.DeleteCookiesAsync("https://example.com", "session"); Defensive patterns
Strategy: validation
Validate before calling
// Wait for store readiness before deleting cookies.
await Task.Run(() => { while (!storeReady) { /* spin or await init task */ } });
await cm.DeleteCookiesAsync(url, name); Try / catch
try
{
return await cm.DeleteCookiesAsync(url, name);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("not initialized"))
{
await Task.Delay(50);
return await cm.DeleteCookiesAsync(url, name); // one retry after init
} Prevention
- Await store/context initialization before issuing cookie operations.
- Use the global cookie manager (ready after Cef.Initialize) for non-scoped needs.
- In tests, gate cookie calls on the browser/context initialized event.
When it happens
Trigger: Calling GetCookieManager().DeleteCookiesAsync(url, name) immediately after obtaining the cookie manager from a freshly created RequestContext, before the store initialization Task has run to completion. Common in startup code, automated tests, or headless scenarios that race initialization.
Common situations: Calling cookie operations synchronously right after RequestContext/Browser creation; tests that do not await store readiness; an isolated/incognito request context whose store init is delayed; racing the browser load with cookie setup.
Related errors
- RequestContext is null, unable to obtain cookie manager
- IFrame instance is null. Browser has likely not finished ini
- IBrowserHost instance is null. Browser has likely not finish
- IBrowser
- Unable to invoke ExecuteDevToolsMethod on CEF UI Thread.
AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13).
Data as JSON: /api/errors/d5f56c970f0fd7a0.
Report an issue: GitHub.