dotnet/wpf · error · XpsPackagingException

XPS supports only JPG, TIF, WDP, and PNG image types.

Error message

XPS supports only JPG, TIF, WDP, and PNG image types.

What it means

XpsPackagingException with message "XPS supports only JPG, TIF, WDP, and PNG image types." — the human-readable form of the UnsupportedImageType failure in AddImage(ContentType). Thrown when the requested image ContentType is not among JPEG, TIFF, WDP (JPEG XR), or PNG.

Solutions

  1. Re-encode the image as PNG or JPEG before embedding.
  2. Restrict input MIME types at the pipeline entry point to the four supported types.
  3. Wrap AddImage in try-catch on XpsPackagingException to report a friendly conversion message.

Example fix

// before
page.AddImage(new ContentType("image/gif"));
// after
byte[] pngBytes = ConvertToPng(gifBytes); // re-encode
page.AddImage(new ContentType("image/png"));
Defensive patterns

Strategy: fallback

Validate before calling

if (!(new[]{"image/png","image/jpeg","image/tiff","image/vnd.ms-photo"}).Contains(mime)) mime = "image/png"; // re-encode fallback

Try / catch

try { page.AddImage(mime); }
catch (XpsPackagingException ex) when (ex.Message.Contains("JPG, TIF, WDP")) { page.AddImage("image/png"); }

Prevention

When it happens

Trigger: AddImage(new ContentType(...)) with any MIME type outside image/jpeg, image/tiff, image/vnd.ms-photo (wdp), image/png.

Common situations: XPS export pipelines that pass through GIF, BMP, SVG-rasterized or WebP images; older code paths using legacy MIME spellings.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/a3815b2f4483a6df. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs:1250

        internal
        XpsImage
        AddImage(
            ContentType mimeType
            )
        {
            if (null == _metroPart)
            {
                throw new ObjectDisposedException("FixedPageReader");
            }
            ArgumentNullException.ThrowIfNull(mimeType);
            if (ContentType.Empty.AreTypeAndSubTypeEqual(mimeType))
            {
                throw new ArgumentException(SR.Format(SR.ReachPackaging_InvalidContentType, mimeType.ToString()));
            }

            if (!XpsManager.SupportedImageType(mimeType))
            {
                throw new XpsPackagingException(SR.ReachPackaging_UnsupportedImageType);
            }

            //
            // Create the part and writer
            //
            PackagePart metroPart = this.CurrentXpsManager.GenerateUniquePart(mimeType);
            return AddImage(metroPart);
}


        /// <summary>
        /// This method retrieves a image resource part from a Xps
        /// package using the given URI.
        /// </summary>
        /// <param name="uri">
        /// The URI of the image resource to retrieve.
        /// </param>
        /// <returns>

View on GitHub (pinned to 81131a70a4)