{"record":{"id":"094b5bfe94dec68a","repo":"chocolatey/choco","slug":"could-not-find-a-file-in-the-manifest-resource-str","errorCode":null,"errorMessage":"Could not find a file in the manifest resource stream of '{0}' at '{1}'.","messagePattern":"Could not find a file in the manifest resource stream of '(.+?)' at '(.+?)'\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure/extractors/AssemblyFileExtractor.cs","lineNumber":53,"sourceCode":"        /// <param name=\"fileSystem\">The file system.</param>\r\n        /// <param name=\"assembly\">The assembly.</param>\r\n        /// <param name=\"manifestLocation\">The manifest location.</param>\r\n        /// <param name=\"filePath\">The file path.</param>\r\n        /// <param name=\"overwriteExisting\">\r\n        ///   if set to <c>true</c> [overwrite existing].\r\n        /// </param>\r\n        /// <exception cref=\"System.IO.FileNotFoundException\"></exception>\r\n        public static void ExtractTextFileFromAssembly(IFileSystem fileSystem, IAssembly assembly, string manifestLocation, string filePath, bool overwriteExisting = false)\r\n        {\r\n            if (overwriteExisting || !fileSystem.FileExists(filePath))\r\n            {\r\n                fileSystem.EnsureDirectoryExists(fileSystem.GetDirectoryName(filePath));\r\n                var fileText = assembly.GetManifestString(manifestLocation);\r\n                if (string.IsNullOrWhiteSpace(fileText))\r\n                {\r\n                    var errorMessage = \"Could not find a file in the manifest resource stream of '{0}' at '{1}'.\".FormatWith(assembly.FullName, manifestLocation);\r\n                    \"chocolatey\".Log().Error(() => errorMessage);\r\n                    throw new FileNotFoundException(errorMessage);\r\n                }\r\n\r\n                fileSystem.WriteFile(filePath, fileText, Encoding.UTF8);\r\n            }\r\n        }\r\n\r\n        /// <summary>\r\n        ///   Extract binary file from an assembly to a location on disk\r\n        /// </summary>\r\n        /// <param name=\"fileSystem\">The file system.</param>\r\n        /// <param name=\"assembly\">The assembly.</param>\r\n        /// <param name=\"manifestLocation\">The manifest location.</param>\r\n        /// <param name=\"filePath\">The file path.</param>\r\n        /// <param name=\"overwriteExisting\">\r\n        ///   if set to <c>true</c> [overwrite existing].\r\n        /// </param>\r\n        /// <param name=\"throwError\">Throw an error if there are issues</param>\r\n        public static void ExtractBinaryFileFromAssembly(IFileSystem fileSystem, IAssembly assembly, string manifestLocation, string filePath, bool overwriteExisting = false, bool throwError = true)\r","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure/extractors/AssemblyFileExtractor.cs#L35-L71","documentation":"Thrown by AssemblyFileExtractor.ExtractTextFileFromAssembly when the embedded manifest resource string for the given manifestLocation comes back null/whitespace. The method asks the assembly for its manifest string; if the resource is absent or unreadable it logs an error and raises a FileNotFoundException naming the assembly and the missing manifest path.","triggerScenarios":"Calling ExtractTextFileFromAssembly with a manifestLocation that does not match any embedded resource in the assembly, or against an assembly whose embedded resources were stripped/not compiled in. assembly.GetManifestString(manifestLocation) yields empty.","commonSituations":"A Chocolatey build that forgot to embed a template/helper file (.ps1, .txt) as an embedded resource, or a renamed resource path after refactoring. Third-party licensed assemblies missing expected resources on a version mismatch.","solutions":["Verify the manifestLocation string exactly matches the embedded resource name (default namespace + folder path + filename, case-sensitive).","Open the assembly in a decompiler/ILSpy and confirm the resource exists under Resources; re-embed it with Build Action = Embedded Resource if missing.","If the file is legitimately optional, guard the call or skip extraction when the resource is known-absent rather than letting it throw."],"exampleFix":"// before\nAssemblyFileExtractor.ExtractFileFromAssembly(fs, asm, \"chocolatey.templates.old_name.ps1\", outPath);\n\n// after (resource renamed in build)\nAssemblyFileExtractor.ExtractFileFromAssembly(fs, asm, \"chocolatey.templates.new_name.ps1\", outPath);","handlingStrategy":"validation","validationCode":"var names = assembly.GetManifestResourceNames();\nif (Array.IndexOf(names, manifestLocation) < 0)\n    throw new InvalidOperationException(\"Manifest resource '\" + manifestLocation + \"' not present in assembly '\" + assembly.FullName + \"'.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    AssemblyFileExtractor.ExtractTextFileFromAssembly(fs, assembly, manifestLocation, filePath);\n}\ncatch (FileNotFoundException ex) when (ex.Message.Contains(\"manifest resource stream\"))\n{\n    logger.Error(ex.Message + \" Verify the resource is embedded with the correct name and namespace.\");\n    throw;\n}","preventionTips":["Cross-check manifestLocation against GetManifestResourceNames() during build/tests.","Keep embedded resource paths stable across renames; update manifestLocation constants when files move."],"tags":["embedded-resource","manifest","assembly","filenotfound"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}