{"record":{"id":"bfad110d3287935c","repo":"dotnet/wpf","slug":"sr-xpsvalidatingloadermorethanonethumbnailpart","errorCode":null,"errorMessage":"SR.XpsValidatingLoaderMoreThanOneThumbnailPart","messagePattern":"SR\\.XpsValidatingLoaderMoreThanOneThumbnailPart","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs","lineNumber":572,"sourceCode":"                Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri);\n                Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);\n\n                PackagePart targetPart = package.GetPart(targetUri);\n\n                if (!_printTicketContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))\n                {\n                    throw new FileFormatException(SR.XpsValidatingLoaderPrintTicketHasIncorrectType);\n                }\n            }\n\n            checkRels = part.GetRelationshipsByType(_thumbnailRel);\n            count = 0;\n            foreach (PackageRelationship rel in checkRels)\n            {\n                count++;\n                if (count > 1)\n                {\n                    throw new FileFormatException(SR.XpsValidatingLoaderMoreThanOneThumbnailPart);\n                }\n\n                // Also check for existence and type\n                Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri);\n                Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);\n\n                PackagePart targetPart = package.GetPart(targetUri);\n\n                if (!_jpgContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)) &&\n                    !_pngContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))\n                {\n                    throw new FileFormatException(SR.XpsValidatingLoaderThumbnailHasIncorrectType);\n                }\n            }\n\n            // FixedDocument only has restricted font relationships\n            if (_fixedDocumentContentType.AreTypeAndSubTypeEqual(mimeType))\n            {","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs#L554-L590","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nforeach (var rel in part.GetRelationshipsByType(thumbRel).ToList())\n    part.DeleteRelationship(rel.Id);\npart.CreateRelationship(thumbUri, TargetMode.Internal, thumbRel); // still duplicates if others added elsewhere\n// after\nvar existing = part.GetRelationshipsByType(thumbRel).ToList();\nif (existing.Count == 0)\n    part.CreateRelationship(thumbUri, TargetMode.Internal, thumbRel);","handlingStrategy":"validation","validationCode":"var thumbRels = fixedPart.GetRelationshipsByType(thumbnailRel).ToList();\nif (thumbRels.Count > 1)\n    thumbRels.Skip(1).ToList().ForEach(r => fixedPart.DeleteRelationship(r.Id));","typeGuard":"static bool HasAtMostOneThumbnail(PackagePart part, string relType) =>\n    !part.GetRelationshipsByType(relType).Cast<PackageRelationship>().Skip(1).Any();","tryCatchPattern":"try { loader.Load(packageStream); }\ncatch (FileFormatException ex) { // duplicate thumbnail rel: prune extras and reload\n    PruneDuplicateThumbnailRels(packageStream); loader.Load(packageStream); }","preventionTips":["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."],"tags":["xps","thumbnail","package-relationships","validation"],"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"}