{"record":{"id":"0cfad4b384dd57f7","repo":"dotnet/wpf","slug":"0-contenttype-is-not-valid","errorCode":null,"errorMessage":"'{0}' ContentType is not valid.","messagePattern":"'(.+?)' ContentType is not valid\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs","lineNumber":1245,"sourceCode":"\n            return AddImage(new ContentType(mimeType));\n        }\n\n\n        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.","sourceCodeStart":1227,"sourceCodeEnd":1263,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs#L1227-L1263","documentation":"AddImage(ContentType) throws XpsPackagingException(SR.ReachPackaging_UnsupportedImageType) when XpsManager.SupportedImageType(mimeType) returns false, i.e. the ContentType is not one of the image formats XPS supports. XPS only accepts specific image MIME types.","triggerScenarios":"Calling AddImage with a ContentType whose type/subtype is not JPG, TIF, WDP (JPEG XR / vnd.ms-photo), or PNG — e.g. \"image/gif\" or \"image/bmp\".","commonSituations":"Converting documents that embed BMP/GIF images into XPS; deriving the MIME type from a file extension and passing an unsupported one.","solutions":["Convert the image to PNG, JPEG, TIFF, or WDP before adding it.","Check XpsManager.SupportedImageType(mimeType) (or check mime against the allowed list) before calling AddImage.","Map unsupported MIME types to a supported equivalent (e.g. BMP → PNG)."],"exampleFix":"// before\npage.AddImage(new ContentType(\"image/bmp\")); // throws\n// after\nif (!XpsManager.SupportedImageType(ct))\n    ct = new ContentType(\"image/png\"); // convert image first\npage.AddImage(ct);","handlingStrategy":"validation","validationCode":"string[] allowed = { \"image/png\", \"image/jpeg\", \"image/tiff\", \"image/vnd.ms-photo\" };\nif (!allowed.Contains(mimeType)) throw new NotSupportedException($\"{mimeType} is not an XPS-supported image type\");","typeGuard":null,"tryCatchPattern":"try { page.AddImage(ct); }\ncatch (XpsPackagingException) { image = ConvertToSupported(image); page.AddImage(new ContentType(image.Mime)); }","preventionTips":["Normalize all image inputs to PNG/JPEG at ingestion boundaries.","Keep a central allow-list of XPS image MIME types."],"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-22T01:17:13.364Z"}