iOfficeAI/OfficeCLI · critical · InvalidDataException

[Content_Types].xml is empty.

Error message

[Content_Types].xml is empty.

What it means

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.

Solutions

  1. Verify the file is a valid OPC package by opening it in Office or unzipping and checking [Content_Types].xml has a <Types> root.
  2. Re-save the document from its originating application to regenerate a valid manifest.
  3. Do not suppress this error — an empty content-types table means no part MIME types resolve, so any further processing is meaningless.
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the manifest before trusting the package
using var zip = new ZipArchive(File.OpenRead(filePath), ZipArchiveMode.Read);
var ct = zip.Entries.FirstOrDefault(e => e.FullName.Equals("[Content_Types].xml", StringComparison.OrdinalIgnoreCase));
if (ct == null || new StreamReader(ct.Open()).ReadToEnd().Trim().Length == 0)
    throw new InvalidDataException("Package manifest [Content_Types].xml is missing or empty.");

Try / catch

try { var xml = RawXmlHelper.TryReadByZipUri(package, filePath, "[Content_Types].xml"); }
catch (InvalidDataException ex) when (ex.Message.Contains("[Content_Types].xml is empty"))
{ /* abort: package is not a valid OPC container */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/5d492aad7e0d00fa. Report an issue: GitHub.

Appendix: source

Thrown at src/officecli/Core/RawXmlHelper.cs:1199

        // Special case: `[Content_Types].xml` is the OPC package manifest,
        // not a part. System.IO.Packaging.Package does not expose it; read
        // it as a literal zip entry.
        var trimmed = StripUriSuffixes(partPath.AsSpan().Trim()).ToString();
        if (trimmed.TrimStart('/').Equals("[Content_Types].xml", StringComparison.OrdinalIgnoreCase))
        {
            try
            {
                using var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                using var zip = new ZipArchive(fs, ZipArchiveMode.Read);
                var entry = zip.Entries.FirstOrDefault(e =>
                    e.FullName.Equals("[Content_Types].xml", StringComparison.OrdinalIgnoreCase));
                if (entry == null) return null;
                using var es = entry.Open();
                using var er = new StreamReader(es);
                var ec = er.ReadToEnd();
                var es2 = StripXmlProlog(ec);
                return es2.Length == 0
                    ? throw new InvalidDataException("[Content_Types].xml is empty.")
                    : es2;
            }
            catch (Exception ex) when (ex is not InvalidDataException)
            {
                return null;
            }
        }

        var clean = StripUriSuffixes(partPath.AsSpan().Trim()).ToString();
        var target = clean.StartsWith('/') ? clean : "/" + clean;
        Uri uri;
        try { uri = new Uri(target, UriKind.Relative); } catch { return null; }

        Package bclPkg;
        try
        {
            // FileShare.ReadWrite so we coexist with the SDK's existing handle.
            // Package internally opens the underlying stream with

View on GitHub (pinned to 1ced45e900)