{"record":{"id":"132c8a5b8fa50d87","repo":"dotnet/wpf","slug":"string-passed-for-type-is-not-valid","errorCode":null,"errorMessage":"String passed for type is not valid.","messagePattern":"String passed for type is not valid\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs","lineNumber":1225,"sourceCode":"        /// </returns>\n        /// <exception cref=\"ObjectDisposedException\">FixedPageReader has already been disposed</exception>\n        /// <exception cref=\"ArgumentNullException\">imageType is null.</exception>\n        /// <exception cref=\"ArgumentException\">imageType is an empty string.</exception>\n        /// <exception cref=\"SR.ReachPackaging_UnsupportedImageType\">Unsupported image type</exception>\n        public\n        XpsImage\n        AddImage(\n            string  mimeType\n            )\n        {\n            if (null == _metroPart)\n            {\n                throw new ObjectDisposedException(\"FixedPageReader\");\n            }\n            ArgumentNullException.ThrowIfNull(mimeType);\n            if (0 == mimeType.Length)\n            {\n                throw new ArgumentException(SR.ReachPackaging_InvalidType);\n            }\n\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))","sourceCodeStart":1207,"sourceCodeEnd":1243,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs#L1207-L1243","documentation":"FixedPageReader.AddImage(string) throws ArgumentException(SR.ReachPackaging_InvalidType) when the mimeType string is empty (length 0). A null mimeType would already fail via ArgumentNullException.ThrowIfNull; an empty string is rejected because a MIME type must have a type/subtype.","triggerScenarios":"Calling AddImage(\"\") on an XpsFixedPageReaderWriter whose part is still live.","commonSituations":"MIME type read from an empty config field, a failed lookup, or a string variable default-initialized to empty string.","solutions":["Pass a valid image MIME type such as \"image/png\", \"image/jpeg\", \"image/tiff\", or \"image/vnd.ms-photo\".","Validate the MIME string is non-empty before calling AddImage."],"exampleFix":"// before\nstring mime = config[\"ImageMime\"]; // \"\"\npage.AddImage(mime);\n// after\nstring mime = config[\"ImageMime\"] ?? \"image/png\";\nif (string.IsNullOrEmpty(mime)) throw new InvalidOperationException(\"Image MIME type required\");\npage.AddImage(mime);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(mimeType)) throw new ArgumentException(\"MIME type must be non-empty\", nameof(mimeType));","typeGuard":null,"tryCatchPattern":"try { page.AddImage(mime); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"type\")) { /* substitute default: */ page.AddImage(\"image/png\"); }","preventionTips":["Validate configuration-driven MIME strings before use.","Use constants for the four supported XPS image MIME types instead of free-form strings."],"tags":["wpf","xps","argument","mime-type"],"backgroundTag":"empty-required-field","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"}