{"record":{"id":"5d492aad7e0d00fa","repo":"iOfficeAI/OfficeCLI","slug":"content-types-xml-is-empty","errorCode":null,"errorMessage":"[Content_Types].xml is empty.","messagePattern":"\\[Content_Types\\]\\.xml is empty\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"critical","filePath":"src/officecli/Core/RawXmlHelper.cs","lineNumber":1199,"sourceCode":"        // Special case: `[Content_Types].xml` is the OPC package manifest,\n        // not a part. System.IO.Packaging.Package does not expose it; read\n        // it as a literal zip entry.\n        var trimmed = StripUriSuffixes(partPath.AsSpan().Trim()).ToString();\n        if (trimmed.TrimStart('/').Equals(\"[Content_Types].xml\", StringComparison.OrdinalIgnoreCase))\n        {\n            try\n            {\n                using var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);\n                using var zip = new ZipArchive(fs, ZipArchiveMode.Read);\n                var entry = zip.Entries.FirstOrDefault(e =>\n                    e.FullName.Equals(\"[Content_Types].xml\", StringComparison.OrdinalIgnoreCase));\n                if (entry == null) return null;\n                using var es = entry.Open();\n                using var er = new StreamReader(es);\n                var ec = er.ReadToEnd();\n                var es2 = StripXmlProlog(ec);\n                return es2.Length == 0\n                    ? throw new InvalidDataException(\"[Content_Types].xml is empty.\")\n                    : es2;\n            }\n            catch (Exception ex) when (ex is not InvalidDataException)\n            {\n                return null;\n            }\n        }\n\n        var clean = StripUriSuffixes(partPath.AsSpan().Trim()).ToString();\n        var target = clean.StartsWith('/') ? clean : \"/\" + clean;\n        Uri uri;\n        try { uri = new Uri(target, UriKind.Relative); } catch { return null; }\n\n        Package bclPkg;\n        try\n        {\n            // FileShare.ReadWrite so we coexist with the SDK's existing handle.\n            // Package internally opens the underlying stream with","sourceCodeStart":1181,"sourceCodeEnd":1217,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/RawXmlHelper.cs#L1181-L1217","documentation":"Thrown when the OPC package manifest [Content_Types].xml exists in the zip but, after the XML prolog is stripped, has zero-length content. [Content_Types].xml is the package's required manifest (not a normal part); an empty one makes the package unusable. The throw is InvalidDataException and is deliberately not caught, unlike other IO failures in that block which return null.","triggerScenarios":"Calling raw read on '[Content_Types].xml' (or '/[Content_Types].xml') on a package where the entry is present but empty. The content-types branch at RawXmlHelper.cs:1185 reads the literal zip entry.","commonSituations":"A zip was assembled by hand or by a faulty exporter that created the [Content_Types].xml entry without writing its body. File truncation or a failed save can also leave the manifest empty.","solutions":["Verify the file is a valid OPC package by opening it in Office or unzipping and checking [Content_Types].xml has a <Types> root.","Re-save the document from its originating application to regenerate a valid manifest.","Do not suppress this error — an empty content-types table means no part MIME types resolve, so any further processing is meaningless."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Validate the manifest before trusting the package\nusing var zip = new ZipArchive(File.OpenRead(filePath), ZipArchiveMode.Read);\nvar ct = zip.Entries.FirstOrDefault(e => e.FullName.Equals(\"[Content_Types].xml\", StringComparison.OrdinalIgnoreCase));\nif (ct == null || new StreamReader(ct.Open()).ReadToEnd().Trim().Length == 0)\n    throw new InvalidDataException(\"Package manifest [Content_Types].xml is missing or empty.\");","typeGuard":null,"tryCatchPattern":"try { var xml = RawXmlHelper.TryReadByZipUri(package, filePath, \"[Content_Types].xml\"); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"[Content_Types].xml is empty\"))\n{ /* abort: package is not a valid OPC container */ }","preventionTips":["Reject packages with an empty manifest up front.","Open new/untrusted documents in Office first to confirm validity.","Do not retry on this error — repair or regenerate the file."],"tags":["raw-xml","ooxml","corrupt-package","content-types","invalid-data"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}