{"record":{"id":"5fbffe1a6a5e9325","repo":"dotnet/wpf","slug":"sr-reachpackaging-invalidcontenttype-formatted-with","errorCode":null,"errorMessage":"SR.ReachPackaging_InvalidContentType (formatted with contentType)","messagePattern":"SR\\.ReachPackaging_InvalidContentType \\(formatted with contentType\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs","lineNumber":572,"sourceCode":"            }\n        }\n\n        public\n        override\n        XpsResourceStream\n        AcquireResourceStreamForXpsImage(\n            string resourceId\n            )\n        {\n            XpsResourceStream resourceStream = null;\n\n            ArgumentNullException.ThrowIfNull(resourceId);\n\n            ContentType contentType = new ContentType(resourceId);\n\n            if (ContentType.Empty.AreTypeAndSubTypeEqual(contentType))\n            {\n                throw new ArgumentException(SR.Format(SR.ReachPackaging_InvalidContentType, contentType.ToString()));\n            }\n\n            if (_currentXpsImageRef == 0)\n            {\n                try\n                {\n                    _currentImageType = GetXpsImageTypeFromContentType(contentType);\n                    XpsPrintStream imageStreamWrapper = XpsPrintStream.CreateXpsPrintStream();\n                    Uri imageUri = _xpsManager.GenerateUniqueUri(contentType);\n                    _imageResourceStream = new XpsResourceStream(imageStreamWrapper, imageUri);\n                    IStream imageIStream = imageStreamWrapper.GetManagedIStream();\n\n                    IOpcPartUri partUri = GenerateIOpcPartUri(imageUri);\n                    IXpsOMImageResource imageResource = _xpsOMFactory.CreateImageResource(imageIStream, _currentImageType, partUri);\n                    IXpsOMImageResourceCollection imageCollection = _xpsPartResources.GetImageResources();\n                    imageCollection.Append(imageResource);\n                }\n                catch (COMException)","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs#L554-L590","documentation":"AcquireResourceStreamForXpsImage parses resourceId as a ContentType and rejects empty type/subtype. If the id is empty or has no type+subtype (AreTypeAndSubTypeEqual against ContentType.Empty), ArgumentException with SR.ReachPackaging_InvalidContentType and the offending contentType string is thrown.","triggerScenarios":"Passing an empty string or a string without a valid MIME-like type/subtype (e.g. \"\", \"/images/a.png\", \"jpeg\" without a subtype) as the resourceId to AcquireResourceStreamForXpsImage.","commonSituations":"Image resource ids derived from missing URI extensions; hard-coded ids without content types; data binding producing empty strings before serialization.","solutions":["Ensure resourceId is a non-empty, well-formed content type such as \"image/png\" or \"image/jpeg\".","Guard the call: skip or substitute the image when the derived content type is empty.","Derive the content type from the image file extension using a reliable mapping (png/jpeg/tiff/wdp) instead of raw user data."],"exampleFix":"// before\nvar s = policy.AcquireResourceStreamForXpsImage(imagePath); // may be empty/invalid\n// after\nstring contentType = Path.GetExtension(imagePath) == \".png\" ? \"image/png\" : \"image/jpeg\";\nif (!string.IsNullOrEmpty(contentType))\n    var s = policy.AcquireResourceStreamForXpsImage(contentType);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(resourceId) || !resourceId.Contains('/')) throw new ArgumentException($\"Invalid content type: '{resourceId}'\", nameof(resourceId));","typeGuard":"static bool IsValidContentType(string id) => !string.IsNullOrWhiteSpace(id) && id.Contains('/') && id.IndexOf('/') < id.Length - 1;","tryCatchPattern":"try { var s = policy.AcquireResourceStreamForXpsImage(id); }\ncatch (ArgumentException ex) { log($\"Bad content type '{id}' for XPS image\", ex); }","preventionTips":["Pass MIME-like ids such as \"image/png\" or \"image/jpeg\"","Derive content type from file extension with a fixed map","Validate non-empty before calling","Only use types the pipeline supports (jpeg/png/tiff/wdp)"],"tags":["wpf","xps","images","argument"],"backgroundTag":"invalid-argument-format","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"}