{"record":{"id":"04d21d0115aa38de","repo":"dotnet/wpf","slug":"sr-invaliddscontenttype","errorCode":null,"errorMessage":"SR.InvalidDSContentType","messagePattern":"SR\\.InvalidDSContentType","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs","lineNumber":881,"sourceCode":"\n        internal void ValidateDocStructure()\n        {\n            Uri baseUri = BaseUriHelper.GetBaseUri(this);\n\n            if (baseUri.Scheme.Equals(PackUriHelper.UriSchemePack, StringComparison.OrdinalIgnoreCase))\n            {\n                // avoid the case of pack://application,,,\n                if (!baseUri.Host.Equals(BaseUriHelper.PackAppBaseUri.Host) &&\n                    !baseUri.Host.Equals(BaseUriHelper.SiteOfOriginBaseUri.Host))\n                {\n                    Uri structureUri = GetStructureUriFromRelationship(baseUri, _structureRelationshipName);\n                    if (structureUri != null)\n                    {\n                        ContentType mimeType;\n                        ValidateAndLoadPartFromAbsoluteUri(structureUri, true, \"DocumentStructure\", out mimeType);\n                        if (!_documentStructureContentType.AreTypeAndSubTypeEqual(mimeType))\n                        {\n                            throw new FileFormatException(SR.InvalidDSContentType);\n                        }\n                        _hasExplicitStructure = true;\n                    }\n                }\n            }\n        }\n\n\n        internal static StoryFragments GetStoryFragments(FixedPage fixedPage)\n        {\n            object o = null;\n\n            Uri baseUri = BaseUriHelper.GetBaseUri(fixedPage);\n\n            if (baseUri.Scheme.Equals(PackUriHelper.UriSchemePack, StringComparison.OrdinalIgnoreCase))\n            {\n                // avoid the case of pack://application,,,\n                if (!baseUri.Host.Equals(BaseUriHelper.PackAppBaseUri.Host) &&","sourceCodeStart":863,"sourceCodeEnd":899,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs#L863-L899","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Regenerate the XPS package with a correct DocumentStructure part and matching [Content_Types].xml entry.","Fix the part's Content-Type in [Content_Types].xml to the required document-structure MIME type.","Validate the XPS with the XPS/Opc validators to find which part violates the content type contract."],"exampleFix":"// before ([Content_Types].xml in package)\n<Default Extension=\"xml\" ContentType=\"application/xml\" />\n\n// after\n<Override PartName=\"/Documents/1/DocumentStructure.xml\" ContentType=\"application/vnd.ms-package.structured-storage-documentstructure+xml\" />","handlingStrategy":"try-catch","validationCode":"// pre-validate the package part before loading\ncatch-invalid: inspect the part's Content-Type in [Content_Types].xml\n// and confirm it equals the document-structure MIME type before opening the document.","typeGuard":null,"tryCatchPattern":"try\n{\n    var doc = new FixedDocument(xpsStream, loadOptions);\n}\ncatch (FileFormatException ex)\n{\n    logger.LogError(ex, \"XPS package has an invalid DocumentStructure content type; regenerate the package.\");\n}","preventionTips":["Always produce XPS packages with tools that write correct [Content_Types].xml entries.","Validate generated XPS files with the OPC/XPS validation tools before shipping.","Never hand-edit or re-zip XPS parts without updating their Content-Type declarations."],"tags":["wpf","xps","file-format","content-type","package-validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}