{"record":{"id":"29878f41d137151e","repo":"dotnet/wpf","slug":"sr-invalidsfcontenttype","errorCode":null,"errorMessage":"SR.InvalidSFContentType","messagePattern":"SR\\.InvalidSFContentType","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs","lineNumber":910,"sourceCode":"            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) &&\n                    !baseUri.Host.Equals(BaseUriHelper.SiteOfOriginBaseUri.Host))\n                {\n                    Uri structureUri = GetStructureUriFromRelationship(baseUri, _storyFragmentsRelationshipName);\n\n                    if (structureUri != null)\n                    {\n                        ContentType mimeType;\n                        o = ValidateAndLoadPartFromAbsoluteUri(structureUri, false, null, out mimeType);\n                        if (!_storyFragmentsContentType.AreTypeAndSubTypeEqual(mimeType))\n                        {\n                            throw new FileFormatException(SR.InvalidSFContentType);\n                        }\n                        if (!(o is StoryFragments))\n                        {\n                            throw new FileFormatException(SR.InvalidStoryFragmentsMarkup);\n                        }\n                    }\n                }\n            }\n\n            return o as StoryFragments;\n        }\n\n\n        private static object ValidateAndLoadPartFromAbsoluteUri(Uri AbsoluteUriDoc, bool validateOnly, string rootElement, out ContentType mimeType)\n        {\n            mimeType = null;\n            Stream pageStream = null;\n            object o = null;","sourceCodeStart":892,"sourceCodeEnd":928,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs#L892-L928","documentation":"FixedDocument.GetStoryFragments throws FileFormatException with SR.InvalidSFContentType when the StoryFragments part referenced by the package has a MIME content type that does not match the required StoryFragments type. Like the DocumentStructure check, the part is loaded and its ContentType compared type-and-subtype against the expected value; any mismatch aborts the load as a file format error.","triggerScenarios":"Loading an XPS FixedDocument whose StoryFragments part (accessibility/story metadata) declares an incorrect Content-Type in [Content_Types].xml, or whose part was created/written by a generator that labeled it with a generic XML type.","commonSituations":"Third-party XPS producers omitting or mistyping the StoryFragments Override entry; repackaging tools rewriting content types incorrectly; documents edited by hand.","solutions":["Regenerate the XPS so the StoryFragments part carries the required MIME type.","Correct the [Content_Types].xml Override for the StoryFragments part to the proper story-fragments content type.","If story structure is not needed, remove the StoryFragments relationship/part entirely so it is not loaded with a bad type."],"exampleFix":"// before ([Content_Types].xml in package)\n<Default Extension=\"xml\" ContentType=\"application/xml\" />\n\n// after\n<Override PartName=\"/Documents/1/StoryFragments.xml\" ContentType=\"application/vnd.ms-package.story-fragments+xml\" />","handlingStrategy":"try-catch","validationCode":"// pre-validate the package part before loading\n// confirm the StoryFragments part's Content-Type in [Content_Types].xml\n// matches the required story-fragments MIME type.","typeGuard":null,"tryCatchPattern":"try\n{\n    var fragments = fixedDocument.GetStoryFragments();\n}\ncatch (FileFormatException ex)\n{\n    logger.LogError(ex, \"XPS package has an invalid StoryFragments content type.\");\n}","preventionTips":["Ensure the XPS generator declares the StoryFragments Override with the correct MIME type.","Validate XPS packages with OPC validation tools after any repackaging.","Remove unused StoryFragments parts rather than keeping them with wrong content types."],"tags":["wpf","xps","file-format","content-type","accessibility"],"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"}