{"record":{"id":"d5f56c970f0fd7a0","repo":"cefsharp/CefSharp","slug":"cookiemanager-store-is-not-initialized","errorCode":null,"errorMessage":"CookieManager store is not initialized.","messagePattern":"CookieManager store is not initialized\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"CefSharp/Internals/CookieManagerDecorator.cs","lineNumber":58,"sourceCode":"                {\n                    managerReady = x.Result;\n                });\n            }\n        }\n\n        bool ICookieManager.IsDisposed\n        {\n            get { return manager.IsDisposed; }\n        }\n\n        bool ICookieManager.DeleteCookies(string url, string name, IDeleteCookiesCallback callback)\n        {\n            if (managerReady)\n            {\n                return manager.DeleteCookies(url, name, callback);\n            }\n\n            throw new InvalidOperationException(NotInitialziedExceptionMsg);\n        }\n\n        void IDisposable.Dispose()\n        {\n            manager.Dispose();\n        }\n\n        bool ICookieManager.FlushStore(ICompletionCallback callback)\n        {\n            if (managerReady)\n            {\n                return manager.FlushStore(callback);\n            }\n\n            throw new InvalidOperationException(NotInitialziedExceptionMsg);\n        }\n\n        bool ICookieManager.SetCookie(string url, Cookie cookie, ISetCookieCallback callback)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Internals/CookieManagerDecorator.cs#L40-L76","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (races store init)\nvar cm = requestContext.GetCookieManager(null);\nawait cm.DeleteCookiesAsync(\"https://example.com\", \"session\");\n\n// after (wait for readiness)\nvar cm = requestContext.GetCookieManager(null);\n// await the store init task / context initialization first\nawait waitForContextInitTask;\nawait cm.DeleteCookiesAsync(\"https://example.com\", \"session\");","handlingStrategy":"validation","validationCode":"// Wait for store readiness before deleting cookies.\nawait Task.Run(() => { while (!storeReady) { /* spin or await init task */ } });\nawait cm.DeleteCookiesAsync(url, name);","typeGuard":null,"tryCatchPattern":"try\n{\n    return await cm.DeleteCookiesAsync(url, name);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not initialized\"))\n{\n    await Task.Delay(50);\n    return await cm.DeleteCookiesAsync(url, name); // one retry after init\n}","preventionTips":["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."],"tags":["cookie-manager","lifecycle","initialization","race-condition","cefsharp"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}