cefsharp/CefSharp · error · ArgumentNullException

urlRequestClient

Error message

urlRequestClient

What it means

Thrown by the UrlRequest constructor when the urlRequestClient parameter is null. The constructor wraps a managed request into the underlying CefSharp.Core.UrlRequest, and CEF requires a non-null client callback to receive response headers, data, and completion events. Without it there is no way to deliver the asynchronous response back to the caller, so the constructor rejects it immediately.

Source

Thrown at CefSharp.Core/UrlRequest.cs:50

        /// Create a new URL request that is not associated with a specific browser or frame.
        /// Use <see cref="IFrame.CreateUrlRequest(IRequest, IUrlRequestClient)"/> instead if you want the
        /// request to have this association, in which case it may be handled differently.
        /// For requests originating from the browser process: It may be intercepted by the client via <see cref="IResourceRequestHandler"/>  or <see cref="ISchemeHandlerFactory"/>.
        /// POST data may only contain only a single element of type PDE_TYPE_FILE or PDE_TYPE_BYTES.
        /// </summary>
        /// <param name="request">request</param>
        /// <param name="urlRequestClient">url request client</param>
        /// <param name="requestContext">request context associated with this requets.</param>
        public UrlRequest(IRequest request, IUrlRequestClient urlRequestClient, IRequestContext requestContext)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (urlRequestClient == null)
            {
                throw new ArgumentNullException(nameof(urlRequestClient));
            }

            urlRequest = new CefSharp.Core.UrlRequest(request.UnWrap(), urlRequestClient, requestContext?.UnWrap());
        }

        /// <inheritdoc/>
        public bool ResponseWasCached
        {
            get { return urlRequest.ResponseWasCached; }
        }

        /// <inheritdoc/>
        public IResponse Response
        {
            get { return urlRequest.Response; }
        }

        /// <inheritdoc/>

View on GitHub (pinned to 16bc6e0711)

Solutions

  1. Provide a non-null IUrlRequestClient implementation — the constructor requires it; implement OnResponseHeadersReceived/OnReadData/OnRequestComplete.
  2. Prefer IFrame.CreateUrlRequest(request, client) if your request is associated with a frame — that path has frame-level validation.
  3. If using DI, register IUrlRequestClient (or your custom factory) before constructing UrlRequest.

Example fix

// before
var req = new UrlRequest(request, null);

// after
var client = new MyUrlRequestClient(); // implements IUrlRequestClient
var req = new UrlRequest(request, client);
Defensive patterns

Strategy: validation

Validate before calling

if (urlRequestClient == null) throw new ArgumentNullException(nameof(urlRequestClient));
var req = new UrlRequest(request, urlRequestClient, requestContext);

Type guard

public static bool IsValidUrlRequestClient(IUrlRequestClient c) => c != null;

Try / catch

try { var r = new UrlRequest(request, client, ctx); }
catch (ArgumentNullException ex) when (ex.ParamName == "urlRequestClient") { /* assign client */ }

Prevention

When it happens

Trigger: Calling `new UrlRequest(request, null)` or `new UrlRequest(request, null, requestContext)` directly. Also triggered when a factory method or DI container passes null because IUrlRequestClient was never registered.

Common situations: Developers building out-of-browser URL requests (no associated IFrame) who forget to implement/assign the IUrlRequestClient. Migrating from older CefSharp APIs where the callback was optional or used a different signature (e.g. old IUrlRequestCallback). Passing an uninitialized field that was expected to be set in a lifecycle hook that ran later than expected.

Related errors


AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13). Data as JSON: /api/errors/c7564531fe9d7a09. Report an issue: GitHub.