{"record":{"id":"1da5dcbcacbe0d9e","repo":"dotnet/wpf","slug":"thumbnails-support-only-jpg-and-png-image-types","errorCode":null,"errorMessage":"Thumbnails support only JPG and PNG image types.","messagePattern":"Thumbnails support only JPG and PNG image types\\.","errorType":"exception","errorClass":"XpsPackagingException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs","lineNumber":725,"sourceCode":"                propertiesPart = GenerateUniquePart(XpsS0Markup.CoreDocumentPropertiesType );\n                _metroPackage.CreateRelationship(propertiesPart.Uri, TargetMode.Internal, XpsS0Markup.CorePropertiesRelationshipType );\n            }\n            return propertiesPart;\n        }\n\n        public\n        XpsThumbnail\n        AddThumbnail(XpsImageType imageType, INode parent, XpsThumbnail oldThumbnail )\n        {\n            XpsThumbnail newThumbnail = null;\n            if( oldThumbnail != null )\n            {\n                throw new XpsPackagingException(SR.ReachPackaging_AlreadyHasThumbnail);\n            }    \n            if( !( imageType == XpsImageType.JpegImageType ||\n                    imageType == XpsImageType.PngImageType ) )\n            {\n                throw new XpsPackagingException(SR.ReachPackaging_UnsupportedThumbnailImageType);\n            }   \n            newThumbnail = new XpsThumbnail(this,\n                                        parent,\n                                        GenerateUniquePart(ImageTypeToString(imageType))\n                                        );\n            return newThumbnail;\n        }\n\n        public\n        XpsThumbnail\n        EnsureThumbnail( INode parent, PackagePart part )\n        {\n            XpsThumbnail thumbnail = null;\n            PackagePart thumbNailPart = GetThumbnailPart(part);\n            if( thumbNailPart != null )\n            {\n                thumbnail = new XpsThumbnail(this,\n                                            parent,","sourceCodeStart":707,"sourceCodeEnd":743,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs#L707-L743","documentation":"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.","triggerScenarios":"Calling AddThumbnail with an XpsImageType other than JpegImageType or PngImageType (e.g. XpsImageType.TiffImageType or any other image type enum value).","commonSituations":"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.","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."],"exampleFix":"// before\nXpsThumbnail thumb = manager.AddThumbnail(XpsImageType.TiffImageType, node, null);\n// after\nXpsImageType thumbType = (imageType == XpsImageType.JpegImageType || imageType == XpsImageType.PngImageType)\n    ? imageType : XpsImageType.PngImageType;\nXpsThumbnail thumb = manager.AddThumbnail(thumbType, node, null);","handlingStrategy":"validation","validationCode":"bool isSupported = imageType == XpsImageType.JpegImageType || imageType == XpsImageType.PngImageType;\nif (!isSupported) throw new ArgumentException(nameof(imageType));","typeGuard":"bool IsValidThumbnailType(XpsImageType t) => t == XpsImageType.JpegImageType || t == XpsImageType.PngImageType;","tryCatchPattern":"catch (XpsPackagingException ex) { /* fall back to PngImageType */ }","preventionTips":["Centralize thumbnail type selection into one helper that only returns JPEG or PNG.","Never pass page-image types directly to AddThumbnail."],"tags":["xps","packaging","image-type","unsupported-value","wpf"],"backgroundTag":"unsupported-enum-value","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"}