dotnet/wpf · error · FileFormatException
SR.XpsValidatingLoaderMoreThanOneThumbnailPart
Error message
SR.XpsValidatingLoaderMoreThanOneThumbnailPart
What it means
A FixedDocumentSequence, FixedDocument, or FixedPage part may have at most one Thumbnail relationship. ValidateRelationships counts thumbnail relationships on the part and throws FileFormatException when a second one is encountered.
Solutions
- Delete redundant thumbnail relationships so each part has at most one.
- Regenerate the thumbnail once and reuse the same relationship instead of adding new ones.
- Enumerate and prune relationships with GetRelationshipsByType before saving/loading.
- Rebuild the package with a compliant XPS writer.
Example fix
// before
foreach (var rel in part.GetRelationshipsByType(thumbRel).ToList())
part.DeleteRelationship(rel.Id);
part.CreateRelationship(thumbUri, TargetMode.Internal, thumbRel); // still duplicates if others added elsewhere
// after
var existing = part.GetRelationshipsByType(thumbRel).ToList();
if (existing.Count == 0)
part.CreateRelationship(thumbUri, TargetMode.Internal, thumbRel); Defensive patterns
Strategy: validation
Validate before calling
var thumbRels = fixedPart.GetRelationshipsByType(thumbnailRel).ToList();
if (thumbRels.Count > 1)
thumbRels.Skip(1).ToList().ForEach(r => fixedPart.DeleteRelationship(r.Id)); Type guard
static bool HasAtMostOneThumbnail(PackagePart part, string relType) =>
!part.GetRelationshipsByType(relType).Cast<PackageRelationship>().Skip(1).Any(); Try / catch
try { loader.Load(packageStream); }
catch (FileFormatException ex) { // duplicate thumbnail rel: prune extras and reload
PruneDuplicateThumbnailRels(packageStream); loader.Load(packageStream); } Prevention
- Regenerate thumbnails by updating the existing relationship rather than adding new ones.
- When merging documents, de-duplicate thumbnail relationships per part.
- Audit relationship counts after any package editing tool runs.
When it happens
Trigger: Opening an XPS package in which an FDS/FD/FP part carries two or more relationships of the XPS thumbnail type (http://schemas.microsoft.com/xps/2005/06/thumbnail); the count exceeds 1 during part.GetRelationshipsByType enumeration.
Common situations: Thumbnail generator utilities that add a new thumbnail without deleting the old relationship; document merge tools combining two documents each with their own thumbnail rel on the same part; manual OPC editing.
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.XpsValidatingLoaderMoreThanOneDiscardControlInPackage
- SR.XpsValidatingLoaderMoreThanOnePrintTicketPart
- Document has more than one Thumbnail relationship.
- Resource_XpsPackageBoundaryViolation
- SR.XpsValidatingLoaderDiscardControlHasIncorrectType
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/bfad110d3287935c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs:572
Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri);
Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);
PackagePart targetPart = package.GetPart(targetUri);
if (!_printTicketContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))
{
throw new FileFormatException(SR.XpsValidatingLoaderPrintTicketHasIncorrectType);
}
}
checkRels = part.GetRelationshipsByType(_thumbnailRel);
count = 0;
foreach (PackageRelationship rel in checkRels)
{
count++;
if (count > 1)
{
throw new FileFormatException(SR.XpsValidatingLoaderMoreThanOneThumbnailPart);
}
// 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);
}
}
// FixedDocument only has restricted font relationships
if (_fixedDocumentContentType.AreTypeAndSubTypeEqual(mimeType))
{View on GitHub (pinned to 81131a70a4)