{"record":{"id":"1e5f6650e921e60a","repo":"dotnet/wpf","slug":"sr-reachpackaging-unsupportedimagetype","errorCode":null,"errorMessage":"SR.ReachPackaging_UnsupportedImageType","messagePattern":"SR\\.ReachPackaging_UnsupportedImageType","errorType":"exception","errorClass":"XpsPackagingException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs","lineNumber":855,"sourceCode":"            if (contentType.AreTypeAndSubTypeEqual(XpsS0Markup.JpgContentType))\n            {\n                return XPS_IMAGE_TYPE.XPS_IMAGE_TYPE_JPEG;\n            }\n            else if (contentType.AreTypeAndSubTypeEqual(XpsS0Markup.PngContentType))\n            {\n                return XPS_IMAGE_TYPE.XPS_IMAGE_TYPE_PNG;\n            }\n            else if (contentType.AreTypeAndSubTypeEqual(XpsS0Markup.TifContentType))\n            {\n                return XPS_IMAGE_TYPE.XPS_IMAGE_TYPE_TIFF;\n            }\n            else if (contentType.AreTypeAndSubTypeEqual(XpsS0Markup.WdpContentType))\n            {\n                return XPS_IMAGE_TYPE.XPS_IMAGE_TYPE_WDP;\n            }\n            else\n            {\n                throw new XpsPackagingException(SR.ReachPackaging_UnsupportedImageType);\n            }\n        }\n\n        private\n        void\n        AddCurrentPageToPackageWriter()\n        {\n            try\n            {\n                _currentFixedPageXmlWriter.Flush();\n                IStream pageMarkupStream = _currentFixedPagePrintStream.GetManagedIStream();\n                IOpcPartUri partUri = GenerateIOpcPartUri(_currentFixedPageUri);\n\n                if (_currentPagePrintTicket == null)\n                {\n                    _currentPagePrintTicket = new PrintTicket();\n                }\n","sourceCodeStart":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs#L837-L873","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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'."],"exampleFix":"// before\nvar gif = new GifBitmapEncoder();\ngif.Frames.Add(frame);\n// hand gif stream to XpsImage -> UnsupportedImageType\n// after\nvar png = new PngBitmapEncoder();\npng.Frames.Add(frame);\nusing (var ms = new MemoryStream()) {\n    png.Save(ms);\n    ms.Position = 0;\n    // give ms to XPS serialization as image/png\n}","handlingStrategy":"validation","validationCode":"string[] supported = { \"image/png\", \"image/jpeg\", \"image/tiff\", \"image/vnd.ms-photo\" };\nbool isSupported = supported.Contains(imageContentType);\nif (!isSupported) throw new InvalidOperationException($\"Convert {imageContentType} to PNG/JPEG before XPS serialization\");","typeGuard":"bool IsXpsSupportedImage(ContentType ct) =>\n    ct.AreTypeAndSubTypeEqual(\"image/png\") ||\n    ct.AreTypeAndSubTypeEqual(\"image/jpeg\") ||\n    ct.AreTypeAndSubTypeEqual(\"image/tiff\") ||\n    ct.AreTypeAndSubTypeEqual(XpsS0Markup.WdpContentType);","tryCatchPattern":null,"preventionTips":["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'"],"tags":["wpf","xps","image","unsupported-format","contenttype"],"backgroundTag":"unsupported-image-type","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"}