{"record":{"id":"6fcc72325e15b740","repo":"cefsharp/CefSharp","slug":"otherrequestcontext","errorCode":null,"errorMessage":"otherRequestContext","messagePattern":"otherRequestContext","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"CefSharp.Core/RequestContext.cs","lineNumber":30,"sourceCode":"namespace CefSharp\n{\n    /// <inheritdoc/>\n    public class RequestContext : IRequestContext\n    {\n        private CefSharp.Core.RequestContext requestContext;\n\n        /// <inheritdoc/>\n        public RequestContext()\n        {\n            requestContext = new CefSharp.Core.RequestContext();\n        }\n\n        /// <inheritdoc/>\n        public RequestContext(IRequestContext otherRequestContext)\n        {\n            if (otherRequestContext == null)\n            {\n                throw new ArgumentNullException(nameof(otherRequestContext));\n            }\n            requestContext = new CefSharp.Core.RequestContext(otherRequestContext);\n        }\n\n        /// <inheritdoc/>\n        public RequestContext(IRequestContext otherRequestContext, IRequestContextHandler requestContextHandler)\n        {\n            if (otherRequestContext == null)\n            {\n                throw new ArgumentNullException(nameof(otherRequestContext));\n            }\n\n            if (requestContextHandler == null)\n            {\n                throw new ArgumentNullException(nameof(requestContextHandler));\n            }\n\n            requestContext = new CefSharp.Core.RequestContext(otherRequestContext, requestContextHandler);","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Core/RequestContext.cs#L12-L48","documentation":"ArgumentNullException(nameof(otherRequestContext)) from the RequestContext(IRequestContext otherRequestContext) constructor in the CefSharp wrapper assembly. This constructor shares storage with an existing request context; passing null has no valid meaning, so it fails fast with the parameter name 'otherRequestContext'.","triggerScenarios":"Calling new RequestContext(null); passing a variable that was never assigned (e.g. reading from a config that returned null); chaining from another API that can legitimately return null IRequestContext and not null-checking.","commonSituations":"Building a derived/shared cookie+cache context for an isolated browser and forgetting to instantiate the parent; refactor where the source context is now lazily created and may still be null on first use.","solutions":["Guard the argument: if (otherRequestContext == null) throw or create a fresh RequestContext first.","If you want a brand-new standalone context, use the parameterless RequestContext() constructor instead of the sharing overload.","Wire the source context creation earlier in startup so the reference is never null by the time you share it.","Enable nullable reference types (<Nullable>enable</Nullable>) so the compiler flags the null at the call site."],"exampleFix":"// before\nvar ctx = new RequestContext(maybeNullParent); // ArgumentNullException\n\n// after\nvar parent = maybeNullParent ?? new RequestContext();\nvar ctx = new RequestContext(parent);","handlingStrategy":"validation","validationCode":"if (otherRequestContext == null) throw new ArgumentException(\"parent context required\");\nvar ctx = new RequestContext(otherRequestContext);","typeGuard":"public static bool IsShareable(IRequestContext c) => c != null && !((c as IDisposable)?.GetType().IsValueType ?? false); // simplify: non-null check\n// Practical guard:\npublic static bool IsValidParent(IRequestContext c) => c != null;","tryCatchPattern":"try { return new RequestContext(parent); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"otherRequestContext\")\n{ /* create a fresh context instead */ return new RequestContext(); }","preventionTips":["Enable <Nullable>enable</Nullable> so null is rejected at compile time","Use the parameterless RequestContext() when you have no parent to share","Construct the parent context earlier in startup"],"tags":["csharp","cefsharp","request-context","argument-null","validation"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}