{"record":{"id":"79f5304484b1cd3d","repo":"cefsharp/CefSharp","slug":"unable-to-create-fileresourcehandler","errorCode":null,"errorMessage":"Unable to create FileResourceHandler","messagePattern":"Unable to create FileResourceHandler","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"CefSharp/Internals/FileResourceHandler.cs","lineNumber":49,"sourceCode":"        /// 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        {\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)\n        {\n            //Should never be called\n            throw new NotImplementedException(\"This method should never be called\");\n        }\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Internals/FileResourceHandler.cs#L31-L67","documentation":"Thrown by the FileResourceHandler constructor when filePath is non-empty but File.Exists returns false. CefStreamReader::CreateForFile would fail or produce an invalid stream for a missing file, so the constructor fails fast with FileNotFoundException (message 'Unable to create FileResourceHandler', fileName = filePath).","triggerScenarios":"Constructing new FileResourceHandler(\"text/html\", path) where path points to a file that does not exist at construction time: wrong working directory, typo, file not yet written, deleted resource, or permission issue making the file invisible to File.Exists.","commonSituations":"Relative paths resolved against the wrong base directory (especially under IIS/desktop vs test runner); deployment that omitted the asset; file generated on demand but not yet present; case-sensitivity mismatch on Linux for Windows-authored paths; permissions hiding the file.","solutions":["Use an absolute path: Path.Combine(AppDomain.CurrentDomain.BaseDirectory, relativePath).","Verify the file exists and is readable before constructing; log the resolved absolute path to diagnose working-directory issues.","Ensure the asset is copied to the output directory (CopyToOutputDirectory) in project settings.","On case-sensitive file systems, confirm the path casing matches exactly."],"exampleFix":"// before\nvar path = \"assets/index.html\";\nreturn new FileResourceHandler(\"text/html\", path);\n\n// after\nvar path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, \"assets\", \"index.html\");\nif (!File.Exists(path)) return null;\nreturn new FileResourceHandler(\"text/html\", path);","handlingStrategy":"validation","validationCode":"var absolute = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, relativePath);\nif (!File.Exists(absolute))\n{\n    return null; // or log and serve a fallback\n}\nreturn new FileResourceHandler(mimeType, absolute);","typeGuard":"static bool FileExistsAndReadable(string path) => !string.IsNullOrEmpty(path) && File.Exists(path);","tryCatchPattern":null,"preventionTips":["Use absolute paths built from AppDomain.CurrentDomain.BaseDirectory or the executable directory.","Mark assets as CopyToOutputDirectory in the project so they ship next to the binary.","On case-sensitive OSes, ensure path casing matches the file exactly.","Log the resolved absolute path when diagnosing missing-file errors."],"tags":["resource-handler","file-not-found","io","path","cefsharp"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}