{"record":{"id":"a3815b2f4483a6df","repo":"dotnet/wpf","slug":"xps-supports-only-jpg-tif-wdp-and-png-image-types","errorCode":null,"errorMessage":"XPS supports only JPG, TIF, WDP, and PNG image types.","messagePattern":"XPS supports only JPG, TIF, WDP, and PNG image types\\.","errorType":"exception","errorClass":"XpsPackagingException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs","lineNumber":1250,"sourceCode":"        internal\n        XpsImage\n        AddImage(\n            ContentType mimeType\n            )\n        {\n            if (null == _metroPart)\n            {\n                throw new ObjectDisposedException(\"FixedPageReader\");\n            }\n            ArgumentNullException.ThrowIfNull(mimeType);\n            if (ContentType.Empty.AreTypeAndSubTypeEqual(mimeType))\n            {\n                throw new ArgumentException(SR.Format(SR.ReachPackaging_InvalidContentType, mimeType.ToString()));\n            }\n\n            if (!XpsManager.SupportedImageType(mimeType))\n            {\n                throw new XpsPackagingException(SR.ReachPackaging_UnsupportedImageType);\n            }\n\n            //\n            // Create the part and writer\n            //\n            PackagePart metroPart = this.CurrentXpsManager.GenerateUniquePart(mimeType);\n            return AddImage(metroPart);\n}\n\n\n        /// <summary>\n        /// This method retrieves a image resource part from a Xps\n        /// package using the given URI.\n        /// </summary>\n        /// <param name=\"uri\">\n        /// The URI of the image resource to retrieve.\n        /// </param>\n        /// <returns>","sourceCodeStart":1232,"sourceCodeEnd":1268,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs#L1232-L1268","documentation":"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.","triggerScenarios":"AddImage(new ContentType(...)) with any MIME type outside image/jpeg, image/tiff, image/vnd.ms-photo (wdp), image/png.","commonSituations":"XPS export pipelines that pass through GIF, BMP, SVG-rasterized or WebP images; older code paths using legacy MIME spellings.","solutions":["Re-encode the image as PNG or JPEG before embedding.","Restrict input MIME types at the pipeline entry point to the four supported types.","Wrap AddImage in try-catch on XpsPackagingException to report a friendly conversion message."],"exampleFix":"// before\npage.AddImage(new ContentType(\"image/gif\"));\n// after\nbyte[] pngBytes = ConvertToPng(gifBytes); // re-encode\npage.AddImage(new ContentType(\"image/png\"));","handlingStrategy":"fallback","validationCode":"if (!(new[]{\"image/png\",\"image/jpeg\",\"image/tiff\",\"image/vnd.ms-photo\"}).Contains(mime)) mime = \"image/png\"; // re-encode fallback","typeGuard":null,"tryCatchPattern":"try { page.AddImage(mime); }\ncatch (XpsPackagingException ex) when (ex.Message.Contains(\"JPG, TIF, WDP\")) { page.AddImage(\"image/png\"); }","preventionTips":["Re-encode GIF/BMP/WebP to PNG or JPEG before XPS export.","Test XPS exports with a matrix of image formats your users supply."],"tags":["wpf","xps","image","unsupported-format"],"backgroundTag":"unsupported-operation","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"}