MiniMax-AI/skills · critical · InvalidOperationException

DOCX does not contain word/document.xml

Error message

DOCX does not contain word/document.xml

What it means

`zip.GetEntry("word/document.xml") ?? throw new InvalidOperationException("DOCX does not contain word/document.xml")` in `XsdValidator.Validate`. Identical structural expectation as the business-rule validator: the XSD validation target is `word/document.xml`, so a package missing it cannot be schema-validated. The throw happens before any XSD logic runs.

Source

Thrown at skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/XsdValidator.cs:13

using System.IO.Compression;
using System.Xml;
using System.Xml.Schema;

namespace MiniMaxAIDocx.Core.Validation;

public class XsdValidator
{
    public ValidationResult Validate(string docxPath, string xsdPath)
    {
        using var zip = ZipFile.OpenRead(docxPath);
        var entry = zip.GetEntry("word/document.xml")
            ?? throw new InvalidOperationException("DOCX does not contain word/document.xml");

        using var stream = entry.Open();
        using var reader = new StreamReader(stream);
        var xmlContent = reader.ReadToEnd();

        return ValidateXml(xmlContent, xsdPath);
    }

    public ValidationResult ValidateXml(string xmlContent, string xsdPath)
    {
        var result = new ValidationResult();
        var settings = new XmlReaderSettings();

        var schemaSet = new XmlSchemaSet();
        schemaSet.Add(null, xsdPath);
        settings.Schemas = schemaSet;
        settings.ValidationType = ValidationType.Schema;
        settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;

View on GitHub (pinned to 60aaae52bb)

Solutions

  1. Verify the file is a real `.docx` and opens in Word.
  2. Convert legacy `.doc` to `.docx` before validating.
  3. Re-acquire the file if it may be corrupt; check the entry list with `zip.Entries` for diagnosis.
  4. Guard: `if (zip.GetEntry("word/document.xml") is null) return InvalidResult("not a docx");`.

Example fix

// before
xsdValidator.Validate("notes.zip", "schema.xsd"); // throws

// after
if (zip.GetEntry("word/document.xml") is null)
    return ValidationResult.Fail("File is not a valid .docx");
xsdValidator.Validate("notes.docx", "schema.xsd");
Defensive patterns

Strategy: validation

Validate before calling

static bool IsOpenableDocx(string path)
{
    using var zip = ZipFile.OpenRead(path);
    return zip.GetEntry("word/document.xml") is not null;
}

if (!IsOpenableDocx(docxPath))
    return ValidationResult.Fail("Not a valid .docx; cannot run XSD validation.");

Type guard

bool ContainsDocumentXml(string docxPath)
{
    using var zip = ZipFile.OpenRead(docxPath);
    return zip.GetEntry("word/document.xml") is not null;
}

Try / catch

try
{
    return xsdValidator.Validate(docxPath, xsdPath);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("document.xml"))
{
    return ValidationResult.Fail($"{docxPath} is not a valid .docx package.");
}

Prevention

When it happens

Trigger: Passing a path to a non-`.docx` ZIP, a corrupt/truncated `.docx`, a `.dotx`/`.docm` with a non-standard layout, or a file where `word/document.xml` was stripped.

Common situations: Wrong file type passed in (legacy `.doc`, plain ZIP), corrupt download, or an OPC package that is technically valid but not a Word document body.

Related errors


AI-assisted analysis of MiniMax-AI/skills@60aaae52bb (2026-08-13). Data as JSON: /api/errors/b5d395af6186703d. Report an issue: GitHub.