{"record":{"id":"a1f800010cc01bbd","repo":"cefsharp/CefSharp","slug":"requestcontexthandler","errorCode":null,"errorMessage":"requestContextHandler","messagePattern":"requestContextHandler","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"CefSharp.Core/RequestContext.cs","lineNumber":45,"sourceCode":"        {\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);\n        }\n\n        /// <inheritdoc/>\n        public RequestContext(IRequestContextHandler requestContextHandler)\n        {\n            if (requestContextHandler == null)\n            {\n                throw new ArgumentNullException(nameof(requestContextHandler));\n            }\n            requestContext = new CefSharp.Core.RequestContext(requestContextHandler);\n        }\n\n        /// <inheritdoc/>\n        public RequestContext(RequestContextSettings settings)\n        {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Core/RequestContext.cs#L27-L63","documentation":"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.","triggerScenarios":"Calling new RequestContext(parent, null) intending 'no handler'; passing a handler field that was never assigned; DI resolving IRequestContextHandler to null.","commonSituations":"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.","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."],"exampleFix":"// before\nvar ctx = new RequestContext(parent, null); // throws\n\n// after - pick the overload that matches intent\nvar ctx = handler == null ? new RequestContext(parent) : new RequestContext(parent, handler);","handlingStrategy":"validation","validationCode":"// If no handler is needed, use the single-arg overload.\nvar ctx = handler == null ? new RequestContext(parent) : new RequestContext(parent, handler);","typeGuard":"public static bool HasHandler(IRequestContextHandler h) => h != null;","tryCatchPattern":"try { return new RequestContext(parent, handler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"requestContextHandler\")\n{ return new RequestContext(parent); }","preventionTips":["Branch on whether a handler exists and choose the matching overload","Use RequestContextBuilder.OnInitialize to attach hooks without null handlers","Enable nullable reference types"],"tags":["csharp","cefsharp","request-context","argument-null","validation","handler"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}