{"record":{"id":"798d52472116eaed","repo":"cefsharp/CefSharp","slug":"browser","errorCode":null,"errorMessage":"browser","messagePattern":"browser","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"CefSharp/WebBrowserExtensions.cs","lineNumber":1952,"sourceCode":"                    }\n\n                    stringBuilder.Append(\", \");\n                }\n\n                //Remove the trailing comma\n                stringBuilder.Remove(stringBuilder.Length - 2, 2);\n            }\n\n            stringBuilder.Append(\");\");\n\n            return stringBuilder.ToString();\n        }\n\n        public static void ThrowExceptionIfChromiumWebBrowserDisposed(IChromiumWebBrowserBase browser)\n        {\n            if (browser == null)\n            {\n                throw new ArgumentNullException(nameof(browser));\n            }\n\n            if (browser.IsDisposed)\n            {\n                // Provide a more meaningful message for WinForms ChromiumHostControl\n                // should be ChromiumWebBrowser/ChromiumHostControl\n                var type = browser.GetType();\n\n                throw new ObjectDisposedException(type.Name);\n            }\n        }\n\n        /// <summary>\n        /// Throw exception if frame null.\n        /// </summary>\n        /// <exception cref=\"Exception\">Thrown when an exception error condition occurs.</exception>\n        /// <param name=\"frame\">The <seealso cref=\"IFrame\"/> instance this method extends.</param>\n        public static void ThrowExceptionIfFrameNull(IFrame frame)","sourceCodeStart":1934,"sourceCodeEnd":1970,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/WebBrowserExtensions.cs#L1934-L1970","documentation":"The message 'browser' is the parameter name from throw new ArgumentNullException(nameof(browser)) inside ThrowExceptionIfChromiumWebBrowserDisposed. It fires when the IWebBrowser passed to an extension method is a null reference - the method cannot check IsDisposed on null, so it rejects the null argument before any disposal logic. (Note: a disposed browser instead throws ObjectDisposedException with the type name, a different message.)","triggerScenarios":"Invoking any CefSharp extension method guarded by ThrowExceptionIfChromiumWebBrowserDisposed (e.g. Load, RegisterResourceHandler, UnRegisterResourceHandler, GetCookieManager) with a null IWebBrowser instance - typically a not-yet-assigned field or a disposed-and-nulled reference.","commonSituations":"Calling extension methods on a browser field before it is assigned (e.g. in a constructor or Form.Load that runs before the ChromiumWebBrowser is created). Using a nullable reference that was set to null after disposal. DI/scoped lifetimes where the browser instance was never resolved.","solutions":["Ensure the ChromiumWebBrowser instance is created before invoking any extension method on it.","Null-check the browser reference before calling: if (browser != null) browser.Load(url);","Fix the object lifecycle: assign the field in InitializeComponent/onInitialized rather than leaving it null.","If using DI, verify the IWebBrowser registration resolves a live instance at the call site."],"exampleFix":"// before\nbrowser.Load(url); // browser is null -> ArgumentNullException 'browser'\n\n// after\nif (browser != null)\n{\n    browser.Load(url);\n}","handlingStrategy":"validation","validationCode":"if (browser != null && !browser.IsDisposed)\n{\n    browser.Load(url);\n}","typeGuard":"static bool IsUsable(IWebBrowser browser) => browser != null && !browser.IsDisposed;","tryCatchPattern":null,"preventionTips":["Assign the ChromiumWebBrowser field before any code that calls extension methods on it.","Null-check browser references in lifecycle-sensitive call sites.","Avoid nulling references on dispose if later code may still reach them."],"tags":["cefsharp","null-reference","argument-validation","lifecycle"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}