MiniMax-AI/skills · critical · InvalidOperationException

Missing word/document.xml

Error message

Missing word/document.xml

What it means

`zip.GetEntry("word/document.xml") ?? throw new InvalidOperationException("Missing word/document.xml")` in `BusinessRuleValidator.Validate`. The validator opens the `.docx` as a ZIP archive and expects the canonical document part. If `word/document.xml` is absent the file is not a valid Word document body, so business-rule checks (margins, fonts, heading hierarchy) cannot run.

Source

Thrown at skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/BusinessRuleValidator.cs:26

    private static readonly XNamespace W = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
    private static readonly XNamespace R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
    private static readonly XNamespace WP = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
    private static readonly XNamespace A = "http://schemas.openxmlformats.org/drawingml/2006/main";

    private const int MinMarginDxa = 360;   // 0.25 inch
    private const int MaxMarginDxa = 4320;  // 3 inches
    private const int MinBodyFontHps = 16;  // 8pt
    private const int MaxBodyFontHps = 144; // 72pt
    private const int MinHeadingFontHps = 20; // 10pt
    private const int MaxHeadingFontHps = 192; // 96pt

    public ValidationResult Validate(string docxPath)
    {
        var result = new ValidationResult();

        using var zip = ZipFile.OpenRead(docxPath);
        var docEntry = zip.GetEntry("word/document.xml")
            ?? throw new InvalidOperationException("Missing word/document.xml");

        var doc = LoadXml(docEntry);
        var body = doc.Root?.Element(W + "body");
        if (body == null)
        {
            result.Errors.Add(Error("Document has no body element"));
            return result;
        }

        ValidateMargins(body, result);
        ValidateFontSizes(body, result);
        ValidateHeadingHierarchy(body, result);
        ValidateTableColumnWidths(body, result);
        ValidateRelationships(zip, doc, result);
        ValidateComments(zip, result);

        return result;
    }

View on GitHub (pinned to 60aaae52bb)

Solutions

  1. Confirm the input is a genuine OOXML `.docx` (open it in Word to verify).
  2. If you have a legacy `.doc`, convert it to `.docx` before validating.
  3. Re-download or re-save the file if it may be truncated/corrupt.
  4. Guard the call: check `zip.GetEntry("word/document.xml") != null` before validating.

Example fix

// before
validator.Validate("report.doc"); // legacy binary — throws

// after
// convert to .docx first (e.g. via LibreOffice: `soffice --convert-to docx report.doc`)
validator.Validate("report.docx");
Defensive patterns

Strategy: validation

Validate before calling

bool IsRealDocx(string path)
{
    if (!path.EndsWith(".docx", StringComparison.OrdinalIgnoreCase)) return false;
    using var zip = ZipFile.OpenRead(path);
    return zip.GetEntry("word/document.xml") is not null;
}

if (!IsRealDocx(docxPath))
    return ValidationResult.Fail("Not a valid .docx (missing word/document.xml).");

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Pointing `Validate` at a file that is not a `.docx`: a `.zip`, `.docx` renamed from another format, a flat OPC file, a corrupt archive, or a template (`.dotx`) whose structure differs. Also a truncated download.

Common situations: Passing a `.doc` (legacy binary) instead of `.docx`, a renamed file, a partially downloaded/corrupt archive, or a non-Office ZIP.

Related errors


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