{"record":{"id":"3af10e0d40deafe7","repo":"cefsharp/CefSharp","slug":"browser-has-already-been-created-requestcontext-m-3af10e","errorCode":null,"errorMessage":"Browser has already been created. RequestContext must be set before the underlying CEF browser is created.","messagePattern":"Browser has already been created\\. RequestContext must be set before the underlying CEF browser is created\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"CefSharp.Wpf/ChromiumWebBrowser.cs","lineNumber":229,"sourceCode":"                {\n                    browserSettings.Dispose();\n                }\n\n                browserSettings = value;\n            }\n        }\n        /// <summary>\n        /// Gets or sets the request context.\n        /// </summary>\n        /// <value>The request context.</value>\n        public IRequestContext RequestContext\n        {\n            get { return requestContext; }\n            set\n            {\n                if (browserCreated)\n                {\n                    throw new Exception(\"Browser has already been created. RequestContext must be \" +\n                                        \"set before the underlying CEF browser is created.\");\n                }\n                if (value != null && !Core.ObjectFactory.RequestContextType.IsAssignableFrom(value.UnWrap().GetType()))\n                {\n                    throw new Exception(string.Format(\"RequestContext can only be of type {0} or null\", Core.ObjectFactory.RequestContextType));\n                }\n                requestContext = value;\n            }\n        }\n        /// <summary>\n        /// Implement <see cref=\"IRenderHandler\"/> and control how the control is rendered\n        /// </summary>\n        /// <value>The render Handler.</value>\n        public IRenderHandler RenderHandler { get; set; }\n        /// <summary>\n        /// Implement <see cref=\"IAccessibilityHandler\" /> to handle events related to accessibility.\n        /// </summary>\n        /// <value>The accessibility handler.</value>","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Wpf/ChromiumWebBrowser.cs#L211-L247","documentation":"Thrown by the WPF ChromiumWebBrowser.RequestContext setter when browserCreated is true. The RequestContext (cookie/cache partition, proxy, preferences) is bound into CEF at browser creation and is immutable afterward; the WPF control creates the browser lazily on load, so assigning RequestContext after load is rejected.","triggerScenarios":"Setting RequestContext after the WPF control has loaded/rendered; data-binding it to a value that resolves post-load; reassigning during/after navigation to switch identity.","commonSituations":"Per-user profiles set after login while the browser is already displayed; XAML binding whose source loads asynchronously; reusing a browser instance and trying to change its session.","solutions":["Assign RequestContext before the control loads (in the constructor or immediately after instantiation).","For per-session isolation, create a new ChromiumWebBrowser with the desired RequestContext rather than reassigning.","If binding in XAML, make the source available at binding init time.","Avoid showing the window / rendering the control before assigning."],"exampleFix":"// before\nBrowser.RequestContext = new RequestContext(settings); // throws after load\n\n// after\nvar rc = new RequestContext(settings);\nvar browser = new ChromiumWebBrowser { RequestContext = rc };\n// then add to visual tree / show","handlingStrategy":"validation","validationCode":"if (!browser.IsBrowserInitialized)\n{\n    browser.RequestContext = new RequestContext(settings);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Assign RequestContext before the control loads.","For runtime identity changes, recreate the ChromiumWebBrowser with a new context.","Make XAML-bound sources available at binding initialization."],"tags":["cefwsharp","wpf","lifecycle","request-context"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}