cefsharp/CefSharp · error · ArgumentNullException
browser
Error message
browser
What it means
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.)
Source
Thrown at CefSharp/WebBrowserExtensions.cs:1952
}
stringBuilder.Append(", ");
}
//Remove the trailing comma
stringBuilder.Remove(stringBuilder.Length - 2, 2);
}
stringBuilder.Append(");");
return stringBuilder.ToString();
}
public static void ThrowExceptionIfChromiumWebBrowserDisposed(IChromiumWebBrowserBase browser)
{
if (browser == null)
{
throw new ArgumentNullException(nameof(browser));
}
if (browser.IsDisposed)
{
// Provide a more meaningful message for WinForms ChromiumHostControl
// should be ChromiumWebBrowser/ChromiumHostControl
var type = browser.GetType();
throw new ObjectDisposedException(type.Name);
}
}
/// <summary>
/// Throw exception if frame null.
/// </summary>
/// <exception cref="Exception">Thrown when an exception error condition occurs.</exception>
/// <param name="frame">The <seealso cref="IFrame"/> instance this method extends.</param>
public static void ThrowExceptionIfFrameNull(IFrame frame)View on GitHub (pinned to 16bc6e0711)
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.
Example fix
// before
browser.Load(url); // browser is null -> ArgumentNullException 'browser'
// after
if (browser != null)
{
browser.Load(url);
} Defensive patterns
Strategy: validation
Validate before calling
if (browser != null && !browser.IsDisposed)
{
browser.Load(url);
} Type guard
static bool IsUsable(IWebBrowser browser) => browser != null && !browser.IsDisposed;
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- propertyInfo
- fieldInfo
- IBrowser instance is null. Browser has likely not finished i
- IBrowser
- Unable to invoke ExecuteDevToolsMethod on CEF UI Thread.
AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13).
Data as JSON: /api/errors/798d52472116eaed.
Report an issue: GitHub.