dotnet/wpf · error · FileFormatException
SR.XpsValidatingLoaderUnsupportedMimeType
Error message
SR.XpsValidatingLoaderUnsupportedMimeType
What it means
XPSS0ValidatingLoader.Load throws FileFormatException (SR.XpsValidatingLoaderUnsupportedMimeType) when validating an XPS part in strict document mode: the root element name in the markup does not equal the root element expected for the part's declared MIME type. The content contradicts its content type, so the loader refuses it.
Solutions
- Fix the part's markup so its root element matches the declared MIME type's schema.
- Correct the part's ContentType in [Content_Types].xml or its relationships to reflect the actual markup.
- Regenerate the XPS package with a compliant producer instead of hand-editing parts.
- Validate the package with XPS tooling before loading.
Example fix
// before: part declared xps-fixeddocument but contains FixedPage markup <FixedPage xmlns="...">...</FixedPage> // after: root matches declared content type <FixedDocument xmlns="...">...</FixedDocument>
Defensive patterns
Strategy: validation
Validate before calling
// peek the first element name and compare to the expected root for the content type
using var reader = XmlReader.Create(stream, XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore });
reader.MoveToContent();
bool rootMatches = reader.Name == "FixedPage"; // expected root for the declared MIME type Type guard
static bool HasExpectedRoot(Stream s, string expectedRoot)
{
using var r = XmlReader.Create(s, new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore });
r.MoveToContent();
return r.Name == expectedRoot;
} Try / catch
try
{
obj = loader.Load(stream, parentUri, pc, mimeType);
}
catch (FileFormatException ex)
{
// content type / root mismatch: reject or repair the package part
} Prevention
- Keep [Content_Types].xml entries consistent with actual part markup
- Never hand-edit XPS part contents; regenerate with a compliant producer
- Verify root element names against the XPS schema per part type
- Run XPS validation tooling on generated packages
When it happens
Trigger: Loading a part inside an XPS package where the XML root element (xpsSchemaValidator.XmlReader.Name) does not match the rootElement string required by the schema for the part's ContentType (XPSS0ValidatingLoader.cs:167), e.g. a part declared as application/vnd.ms-package.xps-fixedpage whose root is not 'FixedPage'.
Common situations: A malformed or hand-edited XPS file where a FixedDocument or ResourceDictionary part contains FixedPage markup or vice versa; wrong MIME type entry in [Content_Types].xml; a renamed root element; tooling that wrote a part with an incorrect content-type mapping.
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.XpsValidatingLoaderDiscardControlHasIncorrectType
- SR.XpsValidatingLoaderDuplicateReference
- SR.XpsValidatingLoaderMoreThanOneThumbnailInPackage
- SR.XpsValidatingLoaderUnlistedResource
- SR.XpsValidatingLoaderUriNotInSamePackage
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e9366c8089e0cbf8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XPSS0ValidatingLoader.cs:167
{
if (!validResources.ContainsKey(absTargetUri))
{
validResources.Add(absTargetUri, false);
}
}
}
}
XpsSchemaValidator xpsSchemaValidator = new XpsSchemaValidator(this, schema, mimeType,
stream, packageUri, partUri);
_validResources.Push(validResources);
if (rootElement != null)
{
xpsSchemaValidator.XmlReader.MoveToContent();
if (!rootElement.Equals(xpsSchemaValidator.XmlReader.Name))
{
throw new FileFormatException(SR.XpsValidatingLoaderUnsupportedMimeType);
}
while (xpsSchemaValidator.XmlReader.Read())
;
}
else
{
obj = XamlReader.Load(xpsSchemaValidator.XmlReader,
pc,
XamlParseMode.Synchronous, true, safeTypes);
}
_validResources.Pop();
}
finally
{
XpsLoadingContext.ActivePackageUri = previousPackageUri;
}
}View on GitHub (pinned to 81131a70a4)