dotnet/wpf · error · XpsPackagingException
SR.ReachPackaging_UnsupportedImageType
Error message
SR.ReachPackaging_UnsupportedImageType
What it means
GetXpsImageTypeFromContentType maps an image part's content type to an XPS_IMAGE_TYPE. Only PNG, JPEG, TIFF and WDP (HD Photo) are supported by the XPS OM; any other content type throws XpsPackagingException with SR.ReachPackaging_UnsupportedImageType.
Solutions
- Convert images to PNG or JPEG before adding them to the document/serialization pipeline (e.g. encode via PngBitmapEncoder or JpegBitmapEncoder).
- If BMP/GIF sources are required, decode with BitmapDecoder and re-encode to PNG/JPEG before creating the XpsImage.
- Check any code that sets ContentType on image parts to ensure only image/png, image/jpeg, image/tiff, or WDP types are used.
- For HD Photo scenarios, ensure the WDP content type 'image/vnd.ms-photo' is used, not 'image/wdp'.
Example fix
// before
var gif = new GifBitmapEncoder();
gif.Frames.Add(frame);
// hand gif stream to XpsImage -> UnsupportedImageType
// after
var png = new PngBitmapEncoder();
png.Frames.Add(frame);
using (var ms = new MemoryStream()) {
png.Save(ms);
ms.Position = 0;
// give ms to XPS serialization as image/png
} Defensive patterns
Strategy: validation
Validate before calling
string[] supported = { "image/png", "image/jpeg", "image/tiff", "image/vnd.ms-photo" };
bool isSupported = supported.Contains(imageContentType);
if (!isSupported) throw new InvalidOperationException($"Convert {imageContentType} to PNG/JPEG before XPS serialization"); Type guard
bool IsXpsSupportedImage(ContentType ct) =>
ct.AreTypeAndSubTypeEqual("image/png") ||
ct.AreTypeAndSubTypeEqual("image/jpeg") ||
ct.AreTypeAndSubTypeEqual("image/tiff") ||
ct.AreTypeAndSubTypeEqual(XpsS0Markup.WdpContentType); Prevention
- Always encode images as PNG or JPEG before adding to a FixedDocument
- Never embed GIF/BMP directly into XPS pipelines
- Verify ContentType strings for image parts
- Use WdpBitmapEncoder only when deliberately targeting WDP and set 'image/vnd.ms-photo'
When it happens
Trigger: AcquireResourceStreamForXpsImage encounters a resource whose ContentType is not one of image/png, image/jpeg, image/tiff, or image/vnd.ms-photo (WDP) — e.g. a GIF or BMP was embedded as an XpsImage during serialization.
Common situations: Using a BitmapEncoder that produced an unsupported format (GIF/BMP) and handing it to XPS serialization; hand-built XPS packages containing non-listed image MIME types; third-party image libraries emitting exotic types into a FixedDocument.
Related errors
- ' ' ContentType is not valid.
- XPS supports only JPG, TIF, WDP, and PNG image types.
- " }} " element found. Expected fixed page element ( }} ).
- ' ' ContentType is not valid.
- 0x8004020a
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1e5f6650e921e60a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs:855
if (contentType.AreTypeAndSubTypeEqual(XpsS0Markup.JpgContentType))
{
return XPS_IMAGE_TYPE.XPS_IMAGE_TYPE_JPEG;
}
else if (contentType.AreTypeAndSubTypeEqual(XpsS0Markup.PngContentType))
{
return XPS_IMAGE_TYPE.XPS_IMAGE_TYPE_PNG;
}
else if (contentType.AreTypeAndSubTypeEqual(XpsS0Markup.TifContentType))
{
return XPS_IMAGE_TYPE.XPS_IMAGE_TYPE_TIFF;
}
else if (contentType.AreTypeAndSubTypeEqual(XpsS0Markup.WdpContentType))
{
return XPS_IMAGE_TYPE.XPS_IMAGE_TYPE_WDP;
}
else
{
throw new XpsPackagingException(SR.ReachPackaging_UnsupportedImageType);
}
}
private
void
AddCurrentPageToPackageWriter()
{
try
{
_currentFixedPageXmlWriter.Flush();
IStream pageMarkupStream = _currentFixedPagePrintStream.GetManagedIStream();
IOpcPartUri partUri = GenerateIOpcPartUri(_currentFixedPageUri);
if (_currentPagePrintTicket == null)
{
_currentPagePrintTicket = new PrintTicket();
}
View on GitHub (pinned to 81131a70a4)