dotnet/wpf · error · FileFormatException
SR.XpsValidatingLoaderThumbnailHasIncorrectType
Error message
SR.XpsValidatingLoaderThumbnailHasIncorrectType
What it means
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.
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.
Example fix
// before PackagePart thumb = pkg.CreatePart(thumbUri, "image/gif"); // after PackagePart thumb = pkg.CreatePart(thumbUri, "image/png");
Defensive patterns
Strategy: validation
Validate before calling
foreach (var rel in fixedPart.GetRelationshipsByType(thumbnailRel)) {
var target = package.GetPart(PackUriHelper.ResolvePartUri(fixedPart.Uri, rel.TargetUri));
var ct = target.ContentType;
if (!ct.Equals("image/jpeg", StringComparison.OrdinalIgnoreCase) &&
!ct.Equals("image/png", StringComparison.OrdinalIgnoreCase))
throw new InvalidDataException($"Thumbnail {target.Uri} must be JPEG or PNG, got {ct}");
} Type guard
static bool IsCompliantThumbnail(PackagePart p) =>
p.ContentType.Equals("image/jpeg", StringComparison.OrdinalIgnoreCase) ||
p.ContentType.Equals("image/png", StringComparison.OrdinalIgnoreCase); Try / catch
try { loader.Load(packageStream); }
catch (FileFormatException ex) { // convert thumbnail to PNG, fix content type, retry
ConvertThumbnailToPng(packageStream); loader.Load(packageStream); } Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
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
- ' ' ContentType is not valid.
- ' ' ContentType is not valid.
- Document has more than one Thumbnail relationship.
- PackagePart URI does not correspond to a FixedDocument.
- PackagePart URI does not correspond to a FixedPage.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/c7de054b3dd391a5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs:584
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))
{
// Check if target of restricted font relationship is present and is actually a font
checkRels = part.GetRelationshipsByType(_restrictedFontRel);
foreach (PackageRelationship rel in checkRels)
{
// Check for existence and type
Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri);
Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);
PackagePart targetPart = package.GetPart(targetUri);
if (!_fontContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)) &&
!_obfuscatedContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))View on GitHub (pinned to 81131a70a4)