dotnet/wpf · error · FileFormatException
SR.XpsValidatingLoaderMoreThanOneThumbnailInPackage
Error message
SR.XpsValidatingLoaderMoreThanOneThumbnailInPackage
What it means
The XPS validating loader enforces that an XPS package contains at most one thumbnail part. While enumerating relationships of type thumbnail on a part, a second relationship was found, so the loader throws FileFormatException to reject the non-conformant package.
Solutions
- Open the package, enumerate the .rels files, and delete all but one thumbnail relationship.
- Regenerate the XPS with a conformant producer that emits exactly one thumbnail.
- Strip the extra thumbnail rels with a script before loading (Package.DeleteRelationship).
- Catch FileFormatException and surface a 'document is malformed' message to the user.
Example fix
// before: two thumbnail rels in _rels/.rels <Relationship Type="http://schemas.microsoft.com/xps/2005/06/thumbnail" Target="thumbnails/one.png" Id="R1"/> <Relationship Type="http://schemas.microsoft.com/xps/2005/06/thumbnail" Target="thumbnails/two.png" Id="R2"/> // after: keep only one <Relationship Type="http://schemas.microsoft.com/xps/2005/06/thumbnail" Target="thumbnails/one.png" Id="R1"/>
Defensive patterns
Strategy: validation
Validate before calling
static int CountThumbnailRels(Package package)
{
int n = 0;
foreach (PackageRelationship rel in package.GetRelationshipsByType("http://schemas.microsoft.com/xps/2005/06/thumbnail")) n++;
return n; // must be <= 1
} Try / catch
try { var doc = XpsDocument.Open(...); }
catch (FileFormatException) { /* strip duplicate thumbnail rels and retry */ } Prevention
- Ensure your packaging tool emits at most one thumbnail relationship.
- Scan all .rels files for duplicate relationship types before distribution.
- Validate merged packages for duplicated relationships.
When it happens
Trigger: Loading an XPS package where a part (typically the package root or FixedDocumentSequence/FixedDocument) declares more than one relationship of type http://schemas.microsoft.com/xps/2005/06/thumbnail.
Common situations: Packages merged from two XPS documents; packaging tools that append a second thumbnail relationship without removing the old one; programmatic package construction adding a thumbnail twice.
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.InvalidDSContentType
- SR.InvalidSFContentType
- SR.XpsValidatingLoaderDuplicateReference
- SR.XpsValidatingLoaderUnlistedResource
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/76b17e5be0469ccf.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs:643
Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);
PackagePart targetPart = package.GetPart(targetUri);
if (!_discardControlContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))
{
throw new FileFormatException(SR.XpsValidatingLoaderDiscardControlHasIncorrectType);
}
}
// This is the XPS payload root part. We also should check if the Package only has at most one thumbnail...
checkRels = package.GetRelationshipsByType(_thumbnailRel);
count = 0;
foreach (PackageRelationship rel in checkRels)
{
count++;
if (count > 1)
{
throw new FileFormatException(SR.XpsValidatingLoaderMoreThanOneThumbnailInPackage);
}
// Also check for existence and type
Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri);
Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);
PackagePart targetPart = package.GetPart(targetUri);
if (!_jpgContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)) &&
!_pngContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))
{
throw new FileFormatException(SR.XpsValidatingLoaderThumbnailHasIncorrectType);
}
}
}
}
privateView on GitHub (pinned to 81131a70a4)