dotnet/wpf · error · FileFormatException

SR.InvalidDSContentType

Error message

SR.InvalidDSContentType

What it means

FixedDocument.ValidateDocStructure throws FileFormatException with SR.InvalidDSContentType when the DocumentStructure part referenced by the XPS package does not have the expected DocumentStructure MIME content type. The document loads the part from its absolute structure URI and verifies the part's ContentTypes are type-and-subtype equal to the required document-structure type; a mismatch means the package is malformed or mislabeled.

Solutions

  1. Regenerate the XPS package with a correct DocumentStructure part and matching [Content_Types].xml entry.
  2. Fix the part's Content-Type in [Content_Types].xml to the required document-structure MIME type.
  3. Validate the XPS with the XPS/Opc validators to find which part violates the content type contract.

Example fix

// before ([Content_Types].xml in package)
<Default Extension="xml" ContentType="application/xml" />

// after
<Override PartName="/Documents/1/DocumentStructure.xml" ContentType="application/vnd.ms-package.structured-storage-documentstructure+xml" />
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate the package part before loading
catch-invalid: inspect the part's Content-Type in [Content_Types].xml
// and confirm it equals the document-structure MIME type before opening the document.

Try / catch

try
{
    var doc = new FixedDocument(xpsStream, loadOptions);
}
catch (FileFormatException ex)
{
    logger.LogError(ex, "XPS package has an invalid DocumentStructure content type; regenerate the package.");
}

Prevention

When it happens

Trigger: Opening an XPS/FixedDocument stream whose package contains a DocumentStructure part with a wrong or missing Content-Type (e.g. plain XML instead of the required document structure type), typically produced by a faulty XPS generator or hand-built package.

Common situations: XPS files generated by third-party tools with incorrect part MIME types; parts renamed or re-zipped without updating [Content_Types].xml; corrupted or truncated downloads.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/04d21d0115aa38de. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs:881

        internal void ValidateDocStructure()
        {
            Uri baseUri = BaseUriHelper.GetBaseUri(this);

            if (baseUri.Scheme.Equals(PackUriHelper.UriSchemePack, StringComparison.OrdinalIgnoreCase))
            {
                // avoid the case of pack://application,,,
                if (!baseUri.Host.Equals(BaseUriHelper.PackAppBaseUri.Host) &&
                    !baseUri.Host.Equals(BaseUriHelper.SiteOfOriginBaseUri.Host))
                {
                    Uri structureUri = GetStructureUriFromRelationship(baseUri, _structureRelationshipName);
                    if (structureUri != null)
                    {
                        ContentType mimeType;
                        ValidateAndLoadPartFromAbsoluteUri(structureUri, true, "DocumentStructure", out mimeType);
                        if (!_documentStructureContentType.AreTypeAndSubTypeEqual(mimeType))
                        {
                            throw new FileFormatException(SR.InvalidDSContentType);
                        }
                        _hasExplicitStructure = true;
                    }
                }
            }
        }


        internal static StoryFragments GetStoryFragments(FixedPage fixedPage)
        {
            object o = null;

            Uri baseUri = BaseUriHelper.GetBaseUri(fixedPage);

            if (baseUri.Scheme.Equals(PackUriHelper.UriSchemePack, StringComparison.OrdinalIgnoreCase))
            {
                // avoid the case of pack://application,,,
                if (!baseUri.Host.Equals(BaseUriHelper.PackAppBaseUri.Host) &&

View on GitHub (pinned to 81131a70a4)