cefsharp/CefSharp · error · ArgumentNullException
requestContextHandler
Error message
requestContextHandler
What it means
ArgumentNullException(nameof(requestContextHandler)) from the two-argument RequestContext(IRequestContext otherRequestContext, IRequestContextHandler requestContextHandler) constructor - the second guard. The parent passed the first check, but the handler is null, which is invalid for this overload because it explicitly pairs a shared context with a handler.
Source
Thrown at CefSharp.Core/RequestContext.cs:45
{
if (otherRequestContext == null)
{
throw new ArgumentNullException(nameof(otherRequestContext));
}
requestContext = new CefSharp.Core.RequestContext(otherRequestContext);
}
/// <inheritdoc/>
public RequestContext(IRequestContext otherRequestContext, IRequestContextHandler requestContextHandler)
{
if (otherRequestContext == null)
{
throw new ArgumentNullException(nameof(otherRequestContext));
}
if (requestContextHandler == null)
{
throw new ArgumentNullException(nameof(requestContextHandler));
}
requestContext = new CefSharp.Core.RequestContext(otherRequestContext, requestContextHandler);
}
/// <inheritdoc/>
public RequestContext(IRequestContextHandler requestContextHandler)
{
if (requestContextHandler == null)
{
throw new ArgumentNullException(nameof(requestContextHandler));
}
requestContext = new CefSharp.Core.RequestContext(requestContextHandler);
}
/// <inheritdoc/>
public RequestContext(RequestContextSettings settings)
{View on GitHub (pinned to 16bc6e0711)
Solutions
- Provide a real IRequestContextHandler implementation; if you do not need hooks, use the single-argument RequestContext(parent) overload instead.
- If you only need lifecycle hooks conditionally, branch: pick the overload based on whether a handler exists.
- Use RequestContextBuilder to fluently attach only the handlers you need without passing null.
- Enable nullable reference types to surface the null at compile time.
Example fix
// before var ctx = new RequestContext(parent, null); // throws // after - pick the overload that matches intent var ctx = handler == null ? new RequestContext(parent) : new RequestContext(parent, handler);
Defensive patterns
Strategy: validation
Validate before calling
// If no handler is needed, use the single-arg overload. var ctx = handler == null ? new RequestContext(parent) : new RequestContext(parent, handler);
Type guard
public static bool HasHandler(IRequestContextHandler h) => h != null;
Try / catch
try { return new RequestContext(parent, handler); }
catch (ArgumentNullException ex) when (ex.ParamName == "requestContextHandler")
{ return new RequestContext(parent); } Prevention
- Branch on whether a handler exists and choose the matching overload
- Use RequestContextBuilder.OnInitialize to attach hooks without null handlers
- Enable nullable reference types
When it happens
Trigger: Calling new RequestContext(parent, null) intending 'no handler'; passing a handler field that was never assigned; DI resolving IRequestContextHandler to null.
Common situations: Assuming the handler is optional in this overload (it is not); reusing a builder that conditionally produces a handler and produces null in the no-op branch.
Related errors
AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13).
Data as JSON: /api/errors/a1f800010cc01bbd.
Report an issue: GitHub.