dotnet/wpf · error · XpsPackagingException
Thumbnails support only JPG and PNG image types.
Error message
Thumbnails support only JPG and PNG image types.
What it means
XpsManager.AddThumbnail validates the requested thumbnail image type and throws XpsPackagingException when the type is neither JpegImageType nor PngImageType. Per the XPS (Open Packaging) specification, thumbnail parts must be JPEG or PNG images; any other XpsImageType is unsupported for thumbnails.
Solutions
- Pass XpsImageType.JpegImageType or XpsImageType.PngImageType only when calling AddThumbnail.
- Add an explicit switch/if that maps non-thumbnail image types to JPEG or PNG before calling AddThumbnail.
- Validate the image type at the call site and refuse invalid values before invoking the API.
Example fix
// before
XpsThumbnail thumb = manager.AddThumbnail(XpsImageType.TiffImageType, node, null);
// after
XpsImageType thumbType = (imageType == XpsImageType.JpegImageType || imageType == XpsImageType.PngImageType)
? imageType : XpsImageType.PngImageType;
XpsThumbnail thumb = manager.AddThumbnail(thumbType, node, null); Defensive patterns
Strategy: validation
Validate before calling
bool isSupported = imageType == XpsImageType.JpegImageType || imageType == XpsImageType.PngImageType; if (!isSupported) throw new ArgumentException(nameof(imageType));
Type guard
bool IsValidThumbnailType(XpsImageType t) => t == XpsImageType.JpegImageType || t == XpsImageType.PngImageType;
Try / catch
catch (XpsPackagingException ex) { /* fall back to PngImageType */ } Prevention
- Centralize thumbnail type selection into one helper that only returns JPEG or PNG.
- Never pass page-image types directly to AddThumbnail.
When it happens
Trigger: Calling AddThumbnail with an XpsImageType other than JpegImageType or PngImageType (e.g. XpsImageType.TiffImageType or any other image type enum value).
Common situations: Using the same image-type constant used for page images (e.g. TIFF) when also writing a thumbnail; a generic code path that picks an image type from configuration and passes it to AddThumbnail without restricting to JPEG/PNG.
Related errors
- Document PackagePart URI is not valid.
- Only writers can call this method.
- Package must contain an XPS PackagePart.
- PackagePart already has associated Thumbnail.
- PackagePart URI does not correspond to a FixedDocument.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1da5dcbcacbe0d9e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs:725
propertiesPart = GenerateUniquePart(XpsS0Markup.CoreDocumentPropertiesType );
_metroPackage.CreateRelationship(propertiesPart.Uri, TargetMode.Internal, XpsS0Markup.CorePropertiesRelationshipType );
}
return propertiesPart;
}
public
XpsThumbnail
AddThumbnail(XpsImageType imageType, INode parent, XpsThumbnail oldThumbnail )
{
XpsThumbnail newThumbnail = null;
if( oldThumbnail != null )
{
throw new XpsPackagingException(SR.ReachPackaging_AlreadyHasThumbnail);
}
if( !( imageType == XpsImageType.JpegImageType ||
imageType == XpsImageType.PngImageType ) )
{
throw new XpsPackagingException(SR.ReachPackaging_UnsupportedThumbnailImageType);
}
newThumbnail = new XpsThumbnail(this,
parent,
GenerateUniquePart(ImageTypeToString(imageType))
);
return newThumbnail;
}
public
XpsThumbnail
EnsureThumbnail( INode parent, PackagePart part )
{
XpsThumbnail thumbnail = null;
PackagePart thumbNailPart = GetThumbnailPart(part);
if( thumbNailPart != null )
{
thumbnail = new XpsThumbnail(this,
parent,View on GitHub (pinned to 81131a70a4)