{"record":{"id":"c43e1d34750bb8f8","repo":"dotnet/wpf","slug":"document-has-more-than-one-thumbnail-relationship","errorCode":null,"errorMessage":"Document has more than one Thumbnail relationship.","messagePattern":"Document has more than one Thumbnail relationship\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs","lineNumber":651,"sourceCode":"            PackageRelationship thumbNailRel = null;\n            PackagePart         thumbNailPart = null;\n            PackageRelationshipCollection thumbnailCollection = null;\n            if( parent != null )\n            {\n                thumbnailCollection = parent.\n                    GetRelationshipsByType(XpsS0Markup.ThumbnailRelationshipName);\n            }\n            else\n            {\n                thumbnailCollection = _metroPackage.\n                    GetRelationshipsByType(XpsS0Markup.ThumbnailRelationshipName);\n            }\n\n            foreach( PackageRelationship rel in thumbnailCollection )\n            {\n                if( thumbNailRel != null )\n                {\n                    throw new InvalidDataException(SR.ReachPackaging_MoreThanOneThumbnailPart);\n                }\n                thumbNailRel =  rel;\n            }\n            if (thumbNailRel != null)\n            {\n                thumbNailPart = _metroPackage.GetPart(PackUriHelper.ResolvePartUri(thumbNailRel.SourceUri, thumbNailRel.TargetUri));\n            }\n            return thumbNailPart;\n        }\n\n        public\n        PackagePart\n        GetPrintTicketPart(Uri documentUri)\n        {\n            PackagePart documentPart = _metroPackage.GetPart( documentUri );\n            PackagePart printTicketPart = null;\n\n            if( documentPart == null )","sourceCodeStart":633,"sourceCodeEnd":669,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs#L633-L669","documentation":"GetThumbnailPart enumerates the thumbnail relationships on the package/document and throws InvalidDataException (SR.ReachPackaging_MoreThanOneThumbnailPart) if more than one Thumbnail relationship is found. OPC/XPS permits only one thumbnail per package/document level, so duplicates make the package invalid for this API.","triggerScenarios":"Calling GetThumbnailPart on a package containing two or more relationships of the thumbnail relationship type, usually written by a non-conforming producer.","commonSituations":"Third-party XPS generators that add a thumbnail per document and also at package level incorrectly; merge tools concatenating packages and carrying over duplicate thumbnails; custom code re-adding a thumbnail without removing the previous relationship.","solutions":["Open the package and delete the extra thumbnail relationships/parts (keep one, typically /Metadata/Thumbnail.jpeg).","Fix the producer code to replace (not append) the thumbnail relationship when setting a new thumbnail.","Re-save the document through the WPF XPS writer so relationships are normalized.","Validate packages with an OPC validator before processing to catch duplicates upstream."],"exampleFix":"// before\ndocumentPart.CreateRelationship(thumbUri, TargetMode.Internal, thumbRelType); // may duplicate\n// after\nvar existing = documentPart.GetRelationshipsByType(thumbRelType).ToList();\nforeach (var rel in existing.Skip(0)) documentPart.DeleteRelationship(rel.Id);\ndocumentPart.CreateRelationship(thumbUri, TargetMode.Internal, thumbRelType);","handlingStrategy":"validation","validationCode":"int thumbCount = documentPart.GetRelationshipsByType(thumbnailRelationshipType).Count();\nif (thumbCount > 1) throw new InvalidDataException(\"Package contains more than one Thumbnail relationship\");","typeGuard":"bool HasSingleThumbnail(PackagePart p) => p.GetRelationshipsByType(thumbnailRelationshipType).Count() <= 1;","tryCatchPattern":"try { return xpsManager.GetThumbnailPart(); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"Thumbnail\")) { /* strip duplicate thumbnail relationships and retry once */ }","preventionTips":["Replace the thumbnail relationship rather than adding a new one on update.","Run OPC conformance validation on packages produced by third-party tools.","Include a package sanitizer step in merge/import pipelines."],"tags":["wpf","xps","thumbnail","corrupt-package"],"backgroundTag":"invalid-state-transition","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"}