{"record":{"id":"00da8b23f3063915","repo":"cefsharp/CefSharp","slug":"browser-has-already-been-created-browsersettings-00da8b","errorCode":null,"errorMessage":"Browser has already been created. BrowserSettings must be set before the underlying CEF browser is created.","messagePattern":"Browser has already been created\\. BrowserSettings must be set before the underlying CEF browser is created\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"CefSharp.Wpf/ChromiumWebBrowser.cs","lineNumber":203,"sourceCode":"        }\n\n        /// <summary>\n        /// WPF Keyboard Handled forwards key events to the underlying browser\n        /// </summary>\n        public IWpfKeyboardHandler WpfKeyboardHandler { get; set; }\n\n        /// <summary>\n        /// Gets or sets the browser settings.\n        /// </summary>\n        /// <value>The browser settings.</value>\n        public IBrowserSettings BrowserSettings\n        {\n            get { return browserSettings; }\n            set\n            {\n                if (browserCreated)\n                {\n                    throw new Exception(\"Browser has already been created. BrowserSettings must be \" +\n                                        \"set before the underlying CEF browser is created.\");\n                }\n\n                //New instance is created in the constructor, if you use\n                //xaml to initialize browser settings then it will also create a new\n                //instance, so we dispose of the old one\n                if (browserSettings != null && browserSettings.AutoDispose)\n                {\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>","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Wpf/ChromiumWebBrowser.cs#L185-L221","documentation":"Thrown by the WPF ChromiumWebBrowser.BrowserSettings setter when browserCreated is true. In WPF the native browser is created lazily (CreateBrowser sets browserCreated at line ~2039, typically when the control is loaded/its visual is rendered), after which settings are frozen into CEF. The WPF setter additionally disposes a previously AutoDispose settings instance, but only if creation has not yet occurred.","triggerScenarios":"Setting BrowserSettings after the WPF control has loaded (Loaded event fired) or after the underlying visual was rendered and CEF creation began; setting it in code-behind after the control is on screen; XAML/data-binding re-evaluation that reassigns settings post-load.","commonSituations":"Data-binding BrowserSettings in XAML to a property whose value arrives after the browser loaded; configuring settings in Window.Loaded; reusing a control instance across navigations and trying to change settings.","solutions":["Set BrowserSettings before the control loads: in the constructor, in XAML via a property bound at construction, or immediately after `new ChromiumWebBrowser()` before adding to the visual tree.","If bound in XAML, ensure the source value is available at binding initialization (not loaded asynchronously later).","To change settings, recreate the ChromiumWebBrowser instance with the new settings rather than reassigning.","Avoid causing the visual to render (showing the window) before the assignment."],"exampleFix":"// before\n<wpf:ChromiumWebBrowser x:Name=\"Browser\" Address=\"about:blank\" Loaded=\"OnLoaded\"/>\nprivate void OnLoaded(...) { Browser.BrowserSettings = new BrowserSettings(); } // throws\n\n// after\n<wpf:ChromiumWebBrowser x:Name=\"Browser\" Address=\"about:blank\"/>\n// in constructor, before window shown:\nBrowser.BrowserSettings = new BrowserSettings();","handlingStrategy":"validation","validationCode":"// Assign before the WPF control loads.\nif (!browser.IsBrowserInitialized)\n{\n    browser.BrowserSettings = new BrowserSettings();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set BrowserSettings in the constructor or right after `new ChromiumWebBrowser()`, before the control loads.","If binding in XAML, ensure the source value is present at binding init, not loaded asynchronously.","To change settings, recreate the browser instance."],"tags":["cefwsharp","wpf","lifecycle","browser-settings"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}