{"record":{"id":"0ea925e477fe2b37","repo":"dotnet/wpf","slug":"sr-invalidparametervalue","errorCode":null,"errorMessage":"SR.InvalidParameterValue","messagePattern":"SR\\.InvalidParameterValue","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs","lineNumber":512,"sourceCode":"                    //If there is no linear white space found we treat the entire remaining string as \n                    //parameter value.\n                    length = s.Length;\n                }\n            }\n            else\n            {\n                //if the parameter value starts with a '\"' then, we need to look for the\n                //pairing '\"' that is not preceded by a \"\\\" [\"\\\" is used to escape the '\"']\n                bool found = false;\n                length = startIndex;\n\n                while (!found)\n                {\n                    int startingLength = ++length;\n                    length = s.Slice(startingLength).IndexOf('\"');\n\n                    if (length == -1)\n                        throw new ArgumentException(SR.InvalidParameterValue);\n                    length += startingLength; // IndexOf result is based on slicing from startingLength\n\n                    if (s[length - 1] != '\\\\')\n                    {\n                        found = true;\n                        length++;\n                    }\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>","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs#L494-L530","documentation":"For quoted parameter values, GetLengthOfParameterValue scans for the closing double-quote. If a value begins with '\"' but no unescaped closing quote exists (an unterminated quoted-string), ArgumentException(SR.InvalidParameterValue) is thrown.","triggerScenarios":"new ContentType(\"text/plain; title=\\\"hello\") — opening quote never closed; also an escaped quote ('\\\"') consuming the intended closing quote so no terminator remains.","commonSituations":"Hand-built quoted values, escaping bugs where backslashes ate the closing quote, truncation of long values in generated files.","solutions":["Close the quoted string: append the missing '\"'.","Fix escaping — use '\\\\\"' for literal quotes so the closing quote is not treated as escaped.","Use an unquoted token value if quoting is unnecessary."],"exampleFix":"// before\nvar ct = new ContentType(\"text/plain; title=\\\"hello\");\n// after\nvar ct = new ContentType(\"text/plain; title=\\\"hello\\\"\");","handlingStrategy":"validation","validationCode":"public static bool QuotedValuesClosed(string s)\n{\n    int inQuotes = 0;\n    for (int i = 0; i < s.Length; i++)\n    {\n        if (s[i] == '\\\\') { i++; continue; }\n        if (s[i] == '\"') inQuotes ^= 1;\n    }\n    return inQuotes == 0;\n}","typeGuard":null,"tryCatchPattern":"try { var ct = new ContentType(value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"value\"))\n{ /* fix quoting: ensure balanced, unescaped closing quote */ }","preventionTips":["Ensure quoted parameter values have balanced, properly escaped quotes.","Escape backslashes and quotes correctly ('\\\\', '\\\"') in generated values.","Prefer unquoted token values when the value contains no special characters."],"tags":["contenttype","mime","quoting","parameters","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"}