{"record":{"id":"5796578d9760fb37","repo":"dotnet/wpf","slug":"sr-invalidtypesubtype","errorCode":null,"errorMessage":"SR.InvalidTypeSubType","messagePattern":"SR\\.InvalidTypeSubType","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs","lineNumber":414,"sourceCode":"            }\n        }\n\n        /// <summary>\n        /// Parses the type ans subType tokens from the string. \n        /// Also verifies if the Tokens are valid as per the grammar.\n        /// </summary>\n        /// <param name=\"typeAndSubType\">substring that has the type and subType of the content type</param>\n        /// <exception cref=\"ArgumentException\">If the typeAndSubType parameter does not have the \"/\" character</exception>\n        private void ParseTypeAndSubType(ReadOnlySpan<char> typeAndSubType)\n        {\n            //okay to trim at this point the end of the string as Linear White Spaces(LWS) chars are allowed here.\n            typeAndSubType = typeAndSubType.TrimEnd(_linearWhiteSpaceChars);\n\n            int forwardSlashPos = typeAndSubType.IndexOf('/');\n            if (forwardSlashPos < 0 || // no slashes\n                typeAndSubType.Slice(forwardSlashPos + 1).IndexOf('/') >= 0) // more than one slash\n            {\n                throw new ArgumentException(SR.InvalidTypeSubType);\n            }\n\n            _type    = ValidateToken(typeAndSubType.Slice(0, forwardSlashPos).ToString());\n            _subType = ValidateToken(typeAndSubType.Slice(forwardSlashPos + 1).ToString());\n        }\n\n        /// <summary>\n        /// Parse the individual parameter=value strings\n        /// </summary>\n        /// <param name=\"parameterAndValue\">This string has the parameter and value pair of the form\n        /// parameter=value</param>\n        /// <exception cref=\"ArgumentException\">If the string does not have the required \"=\"</exception>\n        private void ParseParameterAndValue(ReadOnlySpan<char> parameterAndValue)\n        {\n            while (!parameterAndValue.IsEmpty)\n            {\n                //At this point the first character MUST be a semi-colon\n                //First time through this test is serving more as an assert.","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs#L396-L432","documentation":"ContentType.ParseTypeAndSubType throws this ArgumentException when the type/subType portion of a MIME content-type string does not contain the mandatory '/' separator between type and subtype. The content type string being parsed is structurally invalid per the MIME grammar.","triggerScenarios":"new ContentType(\"textplain\") (missing slash), new ContentType(\"text/plain/extra\"), or empty strings passing earlier checks; also '/' as first or last char.","commonSituations":"Typos in hand-written MIME strings, concatenating base type with an already-typed subtype, misparsed config values.","solutions":["Ensure the value matches 'type/subType' with exactly one slash.","Validate with a regex like ^[^/\\s]+/[^/\\s]+(;.*)?$ before constructing.","Fix the source string (config, constant, file)."],"exampleFix":"// before\nvar ct = new ContentType(\"textplain\");\n// after\nvar ct = new ContentType(\"text/plain\");","handlingStrategy":"validation","validationCode":"public static bool IsTypeSubType(string s)\n{\n    if (string.IsNullOrEmpty(s)) return false;\n    int first = s.IndexOf('/');\n    return first > 0 && first < s.Length - 1 && s.IndexOf('/', first + 1) < 0;\n}","typeGuard":null,"tryCatchPattern":"try { var ct = new ContentType(value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"type/subType\"))\n{ /* log and use a default content type */ }","preventionTips":["Enforce the 'type/subType' shape (exactly one slash, both sides non-empty) before construction.","Keep MIME constants in one place rather than hand-writing them at call sites."],"tags":["contenttype","mime","format","validation","packaging"],"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"}