{"record":{"id":"5d06c3924a3c8f46","repo":"cefsharp/CefSharp","slug":"please-provide-a-valid-mimetype","errorCode":null,"errorMessage":"Please provide a valid mimeType","messagePattern":"Please provide a valid mimeType","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"CefSharp/Internals/ByteArrayResourceHandler.cs","lineNumber":38,"sourceCode":"        /// Underlying byte array that represents the data\n        /// </summary>\n        public byte[] Data { 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=\"ByteArrayResourceHandler\"/> class.\n        /// </summary>\n        /// <param name=\"mimeType\">mimeType</param>\n        /// <param name=\"data\">byte array</param>\n        public ByteArrayResourceHandler(string mimeType, byte[] data)\n        {\n            if (string.IsNullOrEmpty(mimeType))\n            {\n                throw new ArgumentNullException(\"mimeType\", \"Please provide a valid mimeType\");\n            }\n\n            if (data == null)\n            {\n                throw new ArgumentNullException(\"data\", \"Please provide a valid array\");\n            }\n\n            if (data.Length == 0)\n            {\n                throw new Exception(\"Unable to load byte[] with length 0.\");\n            }\n\n            MimeType = mimeType;\n            Data = data;\n        }\n\n        bool IResourceHandler.ProcessRequest(IRequest request, ICallback callback)\n        {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Internals/ByteArrayResourceHandler.cs#L20-L56","documentation":"Thrown by the ByteArrayResourceHandler constructor when the mimeType argument is null or empty. ByteArrayResourceHandler is a placeholder that wraps a byte array for a CefStreamResourceHandler; CEF needs a valid MIME type to generate correct response headers. The guard fails fast rather than handing CEF an undefined content type.","triggerScenarios":"Constructing new ByteArrayResourceHandler(null, data), new ByteArrayResourceHandler(\"\", data), or passing a mimeType variable that was never assigned. Typical in IResourceRequestHandler.GetResourceHandler implementations that serve in-memory content.","commonSituations":"Serving dynamically generated HTML/JSON/images where the MIME type is computed at runtime and may be unset; copying a snippet that omitted the first argument; passing a content-type resolved from an extension lookup that returned null.","solutions":["Pass an explicit, non-empty MIME type such as \"text/html\" or \"application/json\".","If the type is dynamic, resolve it via a lookup (e.g. MimeMapping.GetMimeMap) with a fallback default before constructing the handler.","Guard the value: if (string.IsNullOrEmpty(mimeType)) mimeType = \"application/octet-stream\"; before the constructor call."],"exampleFix":"// before\nvar handler = new ByteArrayResourceHandler(mimeType, bytes);\n\n// after\nif (string.IsNullOrEmpty(mimeType)) mimeType = \"text/html\";\nvar handler = new ByteArrayResourceHandler(mimeType, bytes);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(mimeType))\n{\n    mimeType = \"application/octet-stream\"; // or resolve from file extension\n}\nvar handler = new ByteArrayResourceHandler(mimeType, data);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve MIME types from a map with a fallback default before constructing resource handlers.","Never pass uninitialized mimeType variables into resource handler constructors.","Centralize resource-handler creation behind a helper that validates mimeType and data."],"tags":["resource-handler","validation","mime-type","constructor","cefsharp"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}