{"record":{"id":"3775ba8c493d3b7b","repo":"QL-Win/QuickLook","slug":"compound-file-not-found","errorCode":null,"errorMessage":"Compound file not found.","messagePattern":"Compound file not found\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/CompoundFileBinary/CompoundFileExtractor.cs","lineNumber":48,"sourceCode":"public static partial class CompoundFileExtractor\n{\n    /// <summary>\n    /// Extracts all streams and storages from the compound file at <paramref name=\"compoundFilePath\"/>\n    /// into the specified <paramref name=\"destinationDirectory\"/>. Directory structure inside the compound\n    /// file is preserved.\n    /// </summary>\n    /// <param name=\"compoundFilePath\">Path to the compound file (OLE compound file / structured storage).</param>\n    /// <param name=\"destinationDirectory\">Destination directory to write extracted files and directories to. If it does not exist it will be created.</param>\n    public static void ExtractToDirectory(string compoundFilePath, string destinationDirectory)\n    {\n        if (!Directory.Exists(destinationDirectory))\n        {\n            Directory.CreateDirectory(destinationDirectory);\n        }\n\n        // Ensure the compound file exists\n        if (!File.Exists(compoundFilePath))\n            throw new FileNotFoundException(\"Compound file not found.\", compoundFilePath);\n\n        // Validate magic header for OLE compound file: D0 CF 11 E0 A1 B1 1A E1\n        byte[] magicHeader = [0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1];\n        byte[] header = new byte[8];\n        using (FileStream fs = new(compoundFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))\n        {\n            int read = fs.Read(header, 0, header.Length);\n            if (read < header.Length || !header.SequenceEqual(magicHeader))\n            {\n                throw new InvalidDataException(\"The specified file does not appear to be an OLE Compound File (invalid header).\");\n            }\n        }\n\n        // Open the compound file as an IStorage implementation wrapped by DisposableIStorage.\n        using DisposableIStorage storage = new(compoundFilePath, STGM.DIRECT | STGM.READ | STGM.SHARE_EXCLUSIVE, IntPtr.Zero);\n        IEnumerator<STATSTG> enumerator = storage.EnumElements();\n\n        // Enumerate all elements (streams and storages) at the root of the compound file.","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.ArchiveViewer/CompoundFileBinary/CompoundFileExtractor.cs#L30-L66","documentation":"Thrown by CompoundFileExtractor.ExtractToDirectory when File.Exists(compoundFilePath) is false. This is a FileNotFoundException whose FileName carries the missing path. It fires before any OLE parsing begins.","triggerScenarios":"Calling ExtractToDirectory(compoundFilePath, destinationDirectory) with a path that does not exist: deleted file, wrong path, network share offline, or a relative path resolved against an unexpected working directory.","commonSituations":"User deletes/moves the source file between selection and extraction; a stale path cached from a previous run; a UNC path with the share unmounted; a typo or environment-variable expansion that yielded a non-existent path.","solutions":["Check File.Exists(compoundFilePath) before calling ExtractToDirectory and surface a clear message.","Verify the path is absolute and correctly expanded (Environment.ExpandEnvironmentVariables).","For network paths, confirm the share is reachable before processing.","Catch FileNotFoundException and prompt the user to reselect the file."],"exampleFix":"// before\nCompoundFileExtractor.ExtractToDirectory(path, dest);\n\n// after\nif (!File.Exists(path))\n    throw new FileNotFoundException($\"Compound file not found: {path}\", path);\nCompoundFileExtractor.ExtractToDirectory(path, dest);","handlingStrategy":"validation","validationCode":"// Ensure the compound file exists before extraction.\npublic static void SafeExtract(string compoundFilePath, string dest)\n{\n    if (!File.Exists(compoundFilePath))\n        throw new FileNotFoundException($\"Compound file not found: {compoundFilePath}\", compoundFilePath);\n    CompoundFileExtractor.ExtractToDirectory(compoundFilePath, dest);\n}","typeGuard":null,"tryCatchPattern":"try { CompoundFileExtractor.ExtractToDirectory(path, dest); }\ncatch (FileNotFoundException ex) when (ex.FileName == path)\n{\n    // Source file is gone; prompt user to reselect.\n}","preventionTips":["Check File.Exists before calling the extractor.","Use absolute, environment-expanded paths.","Verify network shares are reachable for UNC paths."],"tags":["ole","compound-file","io","filenotfound","csharp"],"backgroundTag":null,"analyzedSha":"cb5d9c429c81d9796fac469da2a68efb5626946d","analyzedAt":"2026-08-13T11:51:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}