{"record":{"id":"35beb3b05d215039","repo":"dotnet/wpf","slug":"sr-invalidtoken","errorCode":null,"errorMessage":"SR.InvalidToken","messagePattern":"SR\\.InvalidToken","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs","lineNumber":537,"sourceCode":"                    }\n                }\n            }\n            return length - startIndex;\n        }\n\n        /// <summary>\n        /// Validating the given token\n        /// The following checks are being made - \n        /// 1. If all the characters in the token are either ASCII letter or digit.\n        /// 2. If all the characters in the token are either from the remaining allowed character set.\n        /// </summary>\n        /// <param name=\"token\">string token</param>\n        /// <returns>validated string token</returns>\n        /// <exception cref=\"ArgumentException\">If the token is Empty</exception>\n        private static string ValidateToken(string token)\n        {\n            if (string.IsNullOrEmpty(token))\n                throw new ArgumentException(SR.InvalidToken);\n\n            for (int i = 0; i < token.Length; i++)\n            {\n                if (IsAsciiLetterOrDigit(token[i]))\n                    continue;\n                else\n                    if (IsAllowedCharacter(token[i]))\n                        continue;\n                    else\n                        throw new ArgumentException(SR.InvalidToken);\n            }\n\n            return token;\n        }\n\n        /// <summary>\n        /// Validating if the value of a parameter is either a valid token or a \n        /// valid quoted string","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs#L519-L555","documentation":"ContentType.ValidateToken throws this ArgumentException when a MIME token (type, subtype, parameter or value) is empty or contains characters outside the allowed set (ASCII letters/digits and a restricted set of RFC-compliant punctuation, with quoting for token strings). It is a shared grammar validator used while parsing ContentType strings.","triggerScenarios":"Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs:537 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure MIME/ContentType tokens (type, subtype, parameter names and values) contain only allowed RFC-compliant characters","Quote parameter values that contain special characters per the content-type grammar","Catch ArgumentException when parsing untrusted Content-Type strings"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}