cefsharp/CefSharp · error · ArgumentNullException

other

Error message

other

What it means

ArgumentNullException("other") from RequestContextBuilder.WithSharedSettings(IRequestContext other). Sharing storage requires a source context; passing null is meaningless so it fails fast with parameter name 'other' (note: hardcoded string, not nameof). This check runs before ThrowExceptionIfCustomSettingSpecified.

Solutions

  1. Ensure the source IRequestContext is created first (e.g. obtain it from an existing ChromiumWebbrowser.GetRequestContext() or Cef.GetGlobalRequestContext()).
  2. Guard the call: only invoke WithSharedSettings when the source is non-null, otherwise fall back to a custom-settings builder.
  3. Register IRequestContext as a non-null singleton in DI.
  4. Enable nullable reference types to catch the null statically.

Example fix

// before
var ctx = RequestContext.Configure().WithSharedSettings(parent).Create(); // parent null -> throws

// after
var parent = existingBrowser?.GetRequestContext();
var builder = RequestContext.Configure();
if (parent != null) builder = builder.WithSharedSettings(parent);
else builder = builder.WithCachePath(@"C:\cache");
var ctx = builder.Create();
Defensive patterns

Strategy: validation

Validate before calling

if (parent == null) throw new InvalidOperationException("No RequestContext to share.");
var ctx = RequestContext.Configure().WithSharedSettings(parent).Create();

Type guard

public static bool IsShareable(IRequestContext c) => c != null;

Try / catch

try { return RequestContext.Configure().WithSharedSettings(parent).Create(); }
catch (ArgumentNullException ex) when (ex.ParamName == "other")
{ /* fall back to custom settings */ return RequestContext.Configure().WithCachePath(cache).Create(); }

Prevention

When it happens

Trigger: Calling .WithSharedSettings(null) or .WithSharedSettings(unassignedVariable); passing an IRequestContext obtained from a browser that is not yet created; DI resolving IRequestContext to null.

Common situations: Trying to share the global context before it exists; factory returning null; overload/dispose race where the source context was just disposed.

Related errors


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

Appendix: source

Thrown at CefSharp.Core/RequestContextBuilder.cs:202

            {
                _handler = new RequestContextHandler();
            }

            _handler.SetProxyOnContextInitialized(scheme, host, port);

            return this;
        }

        /// <summary>
        /// Shares storage with other RequestContext
        /// </summary>
        /// <param name="other">shares storage with this RequestContext</param>
        /// <returns>Returns RequestContextBuilder instance</returns>
        public RequestContextBuilder WithSharedSettings(IRequestContext other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            ThrowExceptionIfCustomSettingSpecified();

            _otherContext = other;

            return this;
        }
    }
}

View on GitHub (pinned to 16bc6e0711)