{"record":{"id":"1f0868119c5c8858","repo":"cefsharp/CefSharp","slug":"please-provide-a-valid-array","errorCode":null,"errorMessage":"Please provide a valid array","messagePattern":"Please provide a valid array","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"CefSharp/Internals/ByteArrayResourceHandler.cs","lineNumber":43,"sourceCode":"        /// 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        {\n            //Should never be called\n            throw new NotImplementedException(\"This method should never be called\");\n        }\n\n        void IResourceHandler.GetResponseHeaders(IResponse response, out long responseLength, out string redirectUrl)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Internals/ByteArrayResourceHandler.cs#L25-L61","documentation":"Thrown by the ByteArrayResourceHandler constructor when the data byte array is null. The handler exists to serve a byte array to CEF; a null array leaves it nothing to stream, so the constructor rejects it immediately with an ArgumentNullException.","triggerScenarios":"Constructing new ByteArrayResourceHandler(\"text/html\", null) or passing a byte array reference that was never populated (e.g. result of a failed/empty download, a deserialization that returned null, an Encoding.GetBytes on a null string).","commonSituations":"Generating content from a string where the source string was null; reading bytes from a stream that returned null on error; a placeholder/uninitialized field passed into the handler before data is loaded.","solutions":["Ensure the byte array is populated before constructing the handler, e.g. Encoding.UTF8.GetBytes(content).","If the data source can legitimately be empty, guard upstream and skip creating the handler or supply a fallback body.","Return a different resource handler or null from GetResourceHandler when no data is available instead of forcing construction."],"exampleFix":"// before\nvar bytes = content != null ? Encoding.UTF8.GetBytes(content) : null;\nreturn new ByteArrayResourceHandler(\"text/html\", bytes);\n\n// after\nif (content == null) return null;\nvar bytes = Encoding.UTF8.GetBytes(content);\nreturn new ByteArrayResourceHandler(\"text/html\", bytes);","handlingStrategy":"validation","validationCode":"if (data == null)\n{\n    return null; // or throw a clearer domain exception upstream\n}\nreturn new ByteArrayResourceHandler(mimeType, data);","typeGuard":"static bool HasByteArrayData(byte[] data) => data != null && data.Length > 0;","tryCatchPattern":null,"preventionTips":["Null-check content sources (strings, streams) before converting to bytes.","Return null from GetResourceHandler instead of forcing a construction with null data.","Wrap resource-handler creation in a helper that validates inputs."],"tags":["resource-handler","validation","null-reference","constructor","cefsharp"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}