{"record":{"id":"864885f4b6affc84","repo":"dotnet/wpf","slug":"sr-expectingparametervaluepairs","errorCode":null,"errorMessage":"SR.ExpectingParameterValuePairs","messagePattern":"SR\\.ExpectingParameterValuePairs","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs","lineNumber":440,"sourceCode":"        /// 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.\n                if (parameterAndValue[0] != _semicolonSeparator)\n                    throw new ArgumentException(SR.ExpectingSemicolon);\n\n                //At this point if we have just one semicolon, then its an error.\n                //Also, there can be no trailing LWS characters, as we already checked for that\n                //in the constructor.\n                if (parameterAndValue.Length == 1)\n                    throw new ArgumentException(SR.ExpectingParameterValuePairs);\n\n                //Removing the leading ; from the string\n                parameterAndValue = parameterAndValue.Slice(1);\n\n                //okay to trim start as there can be spaces before the begining\n                //of the parameter name.\n                parameterAndValue = parameterAndValue.TrimStart(_linearWhiteSpaceChars);\n\n                int equalSignIndex = parameterAndValue.IndexOf(_equalSeparator);\n\n                if (equalSignIndex <= 0 || equalSignIndex == (parameterAndValue.Length - 1))\n                    throw new ArgumentException(SR.InvalidParameterValuePair);\n\n                int parameterStartIndex = equalSignIndex + 1;\n\n                //Get length of the parameter value\n                int parameterValueLength = GetLengthOfParameterValue(parameterAndValue, parameterStartIndex);\n","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs#L422-L458","documentation":"If, after the expected semicolon, nothing remains in the parameter string, there is a trailing ';' with no parameter=value pair following. ParseParameterAndValue throws ArgumentException(SR.ExpectingParameterValuePairs).","triggerScenarios":"new ContentType(\"text/plain;\") or \"text/plain; charset=utf8;\" — a dangling semicolon at the end of the content type.","commonSituations":"String building with a loop that appends ';' after the last parameter, copy-paste from lists of parameters, template joins with wrong separator logic.","solutions":["Remove trailing semicolons: value.TrimEnd(';') (then re-trim whitespace).","Join parameters with ';' without appending one at the end: string.Join(\";\", parts).","Reject/repair inputs where ';' is the final character before construction."],"exampleFix":"// before\nvar ct = new ContentType(\"text/plain;\");\n// after\nvar ct = new ContentType(\"text/plain\".TrimEnd(';')); // or fix the value to \"text/plain\"","handlingStrategy":"validation","validationCode":"public static string RemoveTrailingSemicolon(string s) =>\n    s.TrimEnd().TrimEnd(';').TrimEnd();","typeGuard":null,"tryCatchPattern":"try { var ct = new ContentType(value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"parameter\"))\n{ value = RemoveTrailingSemicolon(value); }","preventionTips":["When building parameter lists, use string.Join(\";\", parts) instead of appending ';' in a loop.","Check the final character of generated content types."],"tags":["contenttype","mime","parameters","syntax","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"}