{"record":{"id":"c7de054b3dd391a5","repo":"dotnet/wpf","slug":"sr-xpsvalidatingloaderthumbnailhasincorrecttype","errorCode":null,"errorMessage":"SR.XpsValidatingLoaderThumbnailHasIncorrectType","messagePattern":"SR\\.XpsValidatingLoaderThumbnailHasIncorrectType","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs","lineNumber":584,"sourceCode":"            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            {\n                // Check if target of restricted font relationship is present and is actually a font\n                checkRels = part.GetRelationshipsByType(_restrictedFontRel);\n                foreach (PackageRelationship rel in checkRels)\n                {\n                    // 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 (!_fontContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)) &&\n                            !_obfuscatedContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))","sourceCodeStart":566,"sourceCodeEnd":602,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs#L566-L602","documentation":"The target of a Thumbnail relationship must be an image of type image/jpeg or image/png. When the resolved target part's Content Type matches neither, ValidateRelationships throws FileFormatException because XPS only permits JPEG and PNG thumbnails.","triggerScenarios":"Loading an XPS package whose thumbnail relationship points to a part with Content Type image/tiff, image/gif, image/bmp, or a non-image type — detected by the AreTypeAndSubTypeEqual check against _jpgContentType/_pngContentType.","commonSituations":"Tools generating thumbnails in another format (BMP/GIF/TIFF) and linking them; thumbnails copied from documents that allow other image formats; parts with wrong MIME declarations in [Content_Types].xml.","solutions":["Convert the thumbnail image to JPEG or PNG and update its part Content Type accordingly (image/jpeg or image/png).","Point the thumbnail relationship at an existing JPEG/PNG part.","Remove the thumbnail relationship if a compliant thumbnail isn't available (thumbnails are optional).","Check [Content_Types].xml for a mismatch between the file extension and declared Content Type."],"exampleFix":"// before\nPackagePart thumb = pkg.CreatePart(thumbUri, \"image/gif\");\n// after\nPackagePart thumb = pkg.CreatePart(thumbUri, \"image/png\");","handlingStrategy":"validation","validationCode":"foreach (var rel in fixedPart.GetRelationshipsByType(thumbnailRel)) {\n    var target = package.GetPart(PackUriHelper.ResolvePartUri(fixedPart.Uri, rel.TargetUri));\n    var ct = target.ContentType;\n    if (!ct.Equals(\"image/jpeg\", StringComparison.OrdinalIgnoreCase) &&\n        !ct.Equals(\"image/png\", StringComparison.OrdinalIgnoreCase))\n        throw new InvalidDataException($\"Thumbnail {target.Uri} must be JPEG or PNG, got {ct}\");\n}","typeGuard":"static bool IsCompliantThumbnail(PackagePart p) =>\n    p.ContentType.Equals(\"image/jpeg\", StringComparison.OrdinalIgnoreCase) ||\n    p.ContentType.Equals(\"image/png\", StringComparison.OrdinalIgnoreCase);","tryCatchPattern":"try { loader.Load(packageStream); }\ncatch (FileFormatException ex) { // convert thumbnail to PNG, fix content type, retry\n    ConvertThumbnailToPng(packageStream); loader.Load(packageStream); }","preventionTips":["Only produce thumbnails as JPEG or PNG.","Keep [Content_Types].xml entries aligned with actual image data.","Drop thumbnail relationships entirely if no compliant image exists (they are optional)."],"tags":["xps","thumbnail","image","content-type"],"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"}