{"record":{"id":"76b17e5be0469ccf","repo":"dotnet/wpf","slug":"sr-xpsvalidatingloadermorethanonethumbnailinpackage","errorCode":null,"errorMessage":"SR.XpsValidatingLoaderMoreThanOneThumbnailInPackage","messagePattern":"SR\\.XpsValidatingLoaderMoreThanOneThumbnailInPackage","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs","lineNumber":643,"sourceCode":"                    Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);\n\n                    PackagePart targetPart = package.GetPart(targetUri);\n\n                    if (!_discardControlContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))\n                    {\n                        throw new FileFormatException(SR.XpsValidatingLoaderDiscardControlHasIncorrectType);\n                    }\n                }\n\n                // This is the XPS payload root part. We also should check if the Package only has at most one thumbnail...\n                checkRels = package.GetRelationshipsByType(_thumbnailRel);\n                count = 0;\n                foreach (PackageRelationship rel in checkRels)\n                {\n                    count++;\n                    if (count > 1)\n                    {\n                        throw new FileFormatException(SR.XpsValidatingLoaderMoreThanOneThumbnailInPackage);\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        }\n\n        private","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs#L625-L661","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: two thumbnail rels in _rels/.rels\n<Relationship Type=\"http://schemas.microsoft.com/xps/2005/06/thumbnail\" Target=\"thumbnails/one.png\" Id=\"R1\"/>\n<Relationship Type=\"http://schemas.microsoft.com/xps/2005/06/thumbnail\" Target=\"thumbnails/two.png\" Id=\"R2\"/>\n// after: keep only one\n<Relationship Type=\"http://schemas.microsoft.com/xps/2005/06/thumbnail\" Target=\"thumbnails/one.png\" Id=\"R1\"/>","handlingStrategy":"validation","validationCode":"static int CountThumbnailRels(Package package)\n{\n    int n = 0;\n    foreach (PackageRelationship rel in package.GetRelationshipsByType(\"http://schemas.microsoft.com/xps/2005/06/thumbnail\")) n++;\n    return n; // must be <= 1\n}","typeGuard":null,"tryCatchPattern":"try { var doc = XpsDocument.Open(...); }\ncatch (FileFormatException) { /* strip duplicate thumbnail rels and retry */ }","preventionTips":["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."],"tags":["xps","file-format","validation","wpf"],"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"}