{"record":{"id":"569151089ed21ac4","repo":"cefsharp/CefSharp","slug":"request","errorCode":null,"errorMessage":"request","messagePattern":"request","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"CefSharp.Core/UrlRequest.cs","lineNumber":45,"sourceCode":"        {\n\n        }\n\n        /// <summary>\n        /// Create a new URL request that is not associated with a specific browser or frame.\n        /// Use <see cref=\"IFrame.CreateUrlRequest(IRequest, IUrlRequestClient)\"/> instead if you want the\n        /// request to have this association, in which case it may be handled differently.\n        /// For requests originating from the browser process: It may be intercepted by the client via <see cref=\"IResourceRequestHandler\"/>  or <see cref=\"ISchemeHandlerFactory\"/>.\n        /// POST data may only contain only a single element of type PDE_TYPE_FILE or PDE_TYPE_BYTES.\n        /// </summary>\n        /// <param name=\"request\">request</param>\n        /// <param name=\"urlRequestClient\">url request client</param>\n        /// <param name=\"requestContext\">request context associated with this requets.</param>\n        public UrlRequest(IRequest request, IUrlRequestClient urlRequestClient, IRequestContext requestContext)\n        {\n            if (request == null)\n            {\n                throw new ArgumentNullException(nameof(request));\n            }\n\n            if (urlRequestClient == null)\n            {\n                throw new ArgumentNullException(nameof(urlRequestClient));\n            }\n\n            urlRequest = new CefSharp.Core.UrlRequest(request.UnWrap(), urlRequestClient, requestContext?.UnWrap());\n        }\n\n        /// <inheritdoc/>\n        public bool ResponseWasCached\n        {\n            get { return urlRequest.ResponseWasCached; }\n        }\n\n        /// <inheritdoc/>\n        public IResponse Response","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Core/UrlRequest.cs#L27-L63","documentation":"ArgumentNullException(nameof(request)) from the UrlRequest(IRequest request, IUrlRequestClient urlRequestClient, IRequestContext requestContext) constructor in the CefSharp wrapper. Creating an out-of-context URL request requires a non-null IRequest; null fails immediately. The request is unwrapped (request.UnWrap()) before being handed to the core constructor, so it must be a valid wrapper instance.","triggerScenarios":"Calling new UrlRequest(null, client, ctx); passing an IRequest obtained from a handler before it is materialised; reusing a request object after it was disposed so it surfaces as null via a helper.","commonSituations":"Building a custom UrlRequest from a resource request handler and forgetting to construct the IRequest; refactor where the request is now lazily created; code that assumes a callback always supplies a non-null IRequest.","solutions":["Construct the IRequest first (e.g. via frame.CreateRequest() or Cef.UiThreadRunFactory) and pass the non-null reference.","Where possible prefer IFrame.CreateUrlRequest(IRequest, IUrlRequestClient) which associates the request with a frame and avoids manual construction.","Guard the call site: skip UrlRequest creation if request is null and log the upstream source.","Enable nullable reference types and annotate so the compiler flags the null."],"exampleFix":"// before\nvar req = new UrlRequest(maybeNullRequest, client, ctx); // ArgumentNullException\n\n// after\nif (maybeNullRequest == null)\n    throw new InvalidOperationException(\"IRequest not yet materialised for this UrlRequest.\");\nvar req = new UrlRequest(maybeNullRequest, client, ctx);","handlingStrategy":"validation","validationCode":"if (request == null) throw new InvalidOperationException(\"IRequest not materialised.\");\nvar req = new UrlRequest(request, client, ctx);","typeGuard":"public static bool IsUsableRequest(IRequest r) => r != null;","tryCatchPattern":"try { return new UrlRequest(request, client, ctx); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"request\")\n{ /* construct the request first or skip */ throw; }","preventionTips":["Prefer IFrame.CreateUrlRequest over manual UrlRequest construction","Build the IRequest via frame.CreateRequest() before this call","Enable nullable reference types"],"tags":["csharp","cefsharp","url-request","argument-null","validation"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}