dotnet/wpf · error · FileFormatException
SR.InvalidSFContentType
Error message
SR.InvalidSFContentType
What it means
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.
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.
Example fix
// before ([Content_Types].xml in package) <Default Extension="xml" ContentType="application/xml" /> // after <Override PartName="/Documents/1/StoryFragments.xml" ContentType="application/vnd.ms-package.story-fragments+xml" />
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-validate the package part before loading // confirm the StoryFragments part's Content-Type in [Content_Types].xml // matches the required story-fragments MIME type.
Try / catch
try
{
var fragments = fixedDocument.GetStoryFragments();
}
catch (FileFormatException ex)
{
logger.LogError(ex, "XPS package has an invalid StoryFragments content type.");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Third-party XPS producers omitting or mistyping the StoryFragments Override entry; repackaging tools rewriting content types incorrectly; documents edited by hand.
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
- SR.InvalidDSContentType
- ' ' ContentType is not valid.
- PackagePart URI does not correspond to a FixedDocument.
- PackagePart URI does not correspond to a FixedPage.
- SR.XpsValidatingLoaderDiscardControlHasIncorrectType
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/29878f41d137151e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs:910
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) &&
!baseUri.Host.Equals(BaseUriHelper.SiteOfOriginBaseUri.Host))
{
Uri structureUri = GetStructureUriFromRelationship(baseUri, _storyFragmentsRelationshipName);
if (structureUri != null)
{
ContentType mimeType;
o = ValidateAndLoadPartFromAbsoluteUri(structureUri, false, null, out mimeType);
if (!_storyFragmentsContentType.AreTypeAndSubTypeEqual(mimeType))
{
throw new FileFormatException(SR.InvalidSFContentType);
}
if (!(o is StoryFragments))
{
throw new FileFormatException(SR.InvalidStoryFragmentsMarkup);
}
}
}
}
return o as StoryFragments;
}
private static object ValidateAndLoadPartFromAbsoluteUri(Uri AbsoluteUriDoc, bool validateOnly, string rootElement, out ContentType mimeType)
{
mimeType = null;
Stream pageStream = null;
object o = null;View on GitHub (pinned to 81131a70a4)