{"record":{"id":"078848fe0f24d4e7","repo":"cefsharp/CefSharp","slug":"please-provide-a-valid-mimetype-078848","errorCode":null,"errorMessage":"Please provide a valid mimeType","messagePattern":"Please provide a valid mimeType","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"CefSharp/Lagacy/ResourceHandler.cs","lineNumber":83,"sourceCode":"        /// <summary>\n        /// If the ErrorCode is set then the response will be ignored and\n        /// the errorCode returned.\n        /// </summary>\n        public CefErrorCode? ErrorCode { get; set; }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"ResourceHandler\"/> class.\n        /// </summary>\n        /// <param name=\"mimeType\">Optional mimeType defaults to <see cref=\"CefSharp.ResourceHandler.DefaultMimeType\"/></param>\n        /// <param name=\"stream\">Optional Stream - must be set at some point to provide a valid response</param>\n        /// <param name=\"autoDisposeStream\">When true the Stream will be disposed when this instance is Diposed, you will\n        /// be unable to use this ResourceHandler after the Stream has been disposed</param>\n        /// <param name=\"charset\">response charset</param>\n        public ResourceHandler(string mimeType = CefSharp.ResourceHandler.DefaultMimeType, Stream stream = null, bool autoDisposeStream = false, string charset = null)\n        {\n            if (string.IsNullOrEmpty(mimeType))\n            {\n                throw new ArgumentNullException(\"mimeType\", \"Please provide a valid mimeType\");\n            }\n\n            StatusCode = 200;\n            StatusText = \"OK\";\n            MimeType = mimeType;\n            Headers = new NameValueCollection();\n            Stream = stream;\n            AutoDisposeStream = autoDisposeStream;\n            Charset = charset;\n        }\n\n        /// <summary>\n        /// Begin processing the request. If you have the data in memory you can execute the callback\n        /// immediately and return true. For Async processing you would typically spawn a Task to perform processing,\n        /// then return true. When the processing is complete execute callback.Continue(); In your processing Task, simply set\n        /// the StatusCode, StatusText, MimeType, ResponseLength and Stream\n        /// </summary>\n        /// <param name=\"request\">The request object.</param>","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Lagacy/ResourceHandler.cs#L65-L101","documentation":"Thrown by the legacy ResourceHandler constructor when the mimeType argument is null or empty. Although it is a value-required error, the code uses ArgumentNullException with 'mimeType' as the paramName. The parameter defaults to CefSharp.ResourceHandler.DefaultMimeType, so this only fires when the caller explicitly passes null or empty.","triggerScenarios":"Constructing new ResourceHandler(mimeType: null) or new ResourceHandler(\"\") (e.g. forwarding a request MIME type that was unset); code that derives the MIME from content and passes through a null.","commonSituations":"Passing a computed/looked-up MIME that returned null; clearing a header value before constructing; legacy code migrating from an overload that allowed null.","solutions":["Default the argument by not passing it, or pass CefSharp.ResourceHandler.DefaultMimeType explicitly.","Coalesce: mimeType ?? CefSharp.ResourceHandler.DefaultMimeType.","Resolve the MIME from the file extension (e.g. MimeMapping) before constructing.","Validate the MIME is non-empty at the call site."],"exampleFix":"// before\nvar h = new ResourceHandler(mimeType: resolvedMimeType); // null -> throws\n\n// after\nvar mt = string.IsNullOrEmpty(resolvedMimeType) ? CefSharp.ResourceHandler.DefaultMimeType : resolvedMimeType;\nvar h = new ResourceHandler(mimeType: mt);","handlingStrategy":"validation","validationCode":"var mime = string.IsNullOrEmpty(resolved) ? CefSharp.ResourceHandler.DefaultMimeType : resolved;\nvar handler = new ResourceHandler(mime);","typeGuard":null,"tryCatchPattern":"try { var h = new ResourceHandler(mime); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"mimeType\")\n{ var h = new ResourceHandler(CefSharp.ResourceHandler.DefaultMimeType); }","preventionTips":["Coalesce null/empty MIME to DefaultMimeType.","Resolve MIME from extension before constructing.","Omit the argument to take the default."],"tags":["cefsharp","resource-handler","legacy","argument-validation","mime"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}