cefsharp/CefSharp · error · ArgumentNullException

settings

Error message

settings

What it means

ArgumentNullException(nameof(settings)) from the RequestContext(RequestContextSettings settings) constructor. This overload builds a context from explicit settings (cache path, preferences, etc.); the settings object must be non-null. The inner field settings.settings is then passed to the core constructor.

Source

Thrown at CefSharp.Core/RequestContext.cs:66

            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)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            requestContext = new CefSharp.Core.RequestContext(settings.settings);
        }

        /// <inheritdoc/>
        public RequestContext(RequestContextSettings settings, IRequestContextHandler requestContextHandler)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

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

            requestContext = new CefSharp.Core.RequestContext(settings.settings, requestContextHandler);

View on GitHub (pinned to 16bc6e0711)

Solutions

  1. Construct a RequestContextSettings explicitly (e.g. via RequestContextBuilder.WithCachePath(...).Create() or new RequestContextSettings { ... }) before calling.
  2. If overload resolution surprises you, cast or assign to a typed variable to make the target overload explicit.
  3. Use the fluent RequestContextBuilder API which avoids null settings entirely.
  4. Enable nullable reference types and annotate your settings factory return type.

Example fix

// before
var ctx = new RequestContext(LoadSettings()); // returns null -> throws

// after
var settings = LoadSettings() ?? new RequestContextSettings { CachePath = cacheDir };
var ctx = new RequestContext(settings);
Defensive patterns

Strategy: validation

Validate before calling

var settings = LoadSettings() ?? new RequestContextSettings { CachePath = cacheDir };
var ctx = new RequestContext(settings);

Type guard

public static bool HasSettings(RequestContextSettings s) => s != null;

Try / catch

try { return new RequestContext(settings); }
catch (ArgumentNullException ex) when (ex.ParamName == "settings")
{ return new RequestContext(new RequestContextSettings()); }

Prevention

When it happens

Trigger: Calling new RequestContext(null) where the overload resolves to the RequestContextSettings overload; passing a RequestContextSettings built by a builder that returned null; config deserialisation yielding null.

Common situations: Overload-resolution ambiguity where null silently binds to the settings overload; a settings factory that returns null in the no-config branch; refactor dropping the settings construction.

Related errors


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