{"record":{"id":"32dd329215955144","repo":"cefsharp/CefSharp","slug":"please-provide-a-valid-mimetype-32dd32","errorCode":null,"errorMessage":"Please provide a valid mimeType","messagePattern":"Please provide a valid mimeType","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"CefSharp/Internals/FileResourceHandler.cs","lineNumber":39,"sourceCode":"        /// Path of the underlying file\n        /// </summary>\n        public string FilePath { get; private set; }\n\n        /// <summary>\n        /// Gets or sets the Mime Type.\n        /// </summary>\n        public string MimeType { get; set; }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"FileResourceHandler\"/> class.\n        /// </summary>\n        /// <param name=\"mimeType\">mimeType</param>\n        /// <param name=\"filePath\">filePath</param>\n        public FileResourceHandler(string mimeType, string filePath)\n        {\n            if (string.IsNullOrEmpty(mimeType))\n            {\n                throw new ArgumentNullException(\"mimeType\", \"Please provide a valid mimeType\");\n            }\n\n            if (string.IsNullOrEmpty(filePath))\n            {\n                throw new ArgumentNullException(\"filePath\", \"Please provide a valid filePath\");\n            }\n\n            if (!File.Exists(filePath))\n            {\n                throw new FileNotFoundException(\"Unable to create FileResourceHandler\", filePath);\n            }\n\n            MimeType = mimeType;\n            FilePath = filePath;\n        }\n\n        bool IResourceHandler.ProcessRequest(IRequest request, ICallback callback)\n        {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Internals/FileResourceHandler.cs#L21-L57","documentation":"Thrown by the FileResourceHandler constructor when mimeType is null or empty. FileResourceHandler serves a file from disk to CEF via CefStreamReader::CreateForFile; CEF needs a valid MIME type to set response headers, so the constructor rejects an undefined type with ArgumentNullException.","triggerScenarios":"Constructing new FileResourceHandler(null, path) or new FileResourceHandler(\"\", path) in a GetResourceHandler implementation that serves local files. The MIME type is often derived from the extension and may be unset.","commonSituations":"Serving local HTML/JSON/PDF assets where the MIME type is computed at runtime and returned null; copy-paste that omitted the argument; serving a file whose extension has no mapped type.","solutions":["Pass an explicit non-empty MIME type such as \"text/html\" or \"application/pdf\".","Resolve the type from the file extension via a MIME map with a default fallback.","Guard: if (string.IsNullOrEmpty(mimeType)) mimeType = \"application/octet-stream\"; before constructing."],"exampleFix":"// before\nreturn new FileResourceHandler(mimeType, filePath);\n\n// after\nif (string.IsNullOrEmpty(mimeType))\n    mimeType = MimeMapping.GetMimeMap(Path.GetExtension(filePath)) ?? \"application/octet-stream\";\nreturn new FileResourceHandler(mimeType, filePath);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(mimeType))\n{\n    mimeType = \"application/octet-stream\";\n}\nreturn new FileResourceHandler(mimeType, filePath);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve MIME types from a map with a sensible default before constructing file handlers.","Never pass uninitialized mimeType variables into resource handler constructors.","Centralize FileResourceHandler creation behind a validating helper."],"tags":["resource-handler","validation","mime-type","constructor","cefsharp"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}