{"record":{"id":"28f0854abb6166b0","repo":"dotnet/wpf","slug":"sr-expectingsemicolon","errorCode":null,"errorMessage":"SR.ExpectingSemicolon","messagePattern":"SR\\.ExpectingSemicolon","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs","lineNumber":434,"sourceCode":"\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.\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);","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs#L416-L452","documentation":"In ParseParameterAndValue, each remaining parameter segment must begin with a semicolon separating it from the type/subType. If the remainder does not start with ';', the input is malformed and ArgumentException(SR.ExpectingSemicolon) is thrown.","triggerScenarios":"new ContentType(\"text/plain charset=utf8\") or \"text/plain&charset=utf8\" — a separator other than ';' between parameters and the media type.","commonSituations":"Using space or '&' as parameter separator (HTTP-query habits), corrupted strings from external sources.","solutions":["Separate each parameter with a semicolon: \"text/plain; charset=utf8\".","Normalize any alternate separators to ';' before constructing.","Validate the parameter portion against the grammar (starts with ';' after subtype)."],"exampleFix":"// before\nvar ct = new ContentType(\"text/plain charset=utf8\");\n// after\nvar ct = new ContentType(\"text/plain; charset=utf8\");","handlingStrategy":"validation","validationCode":"int slash = s.IndexOf('/');\nint semi = s.IndexOf(';', slash);\nbool ok = semi < 0 || (semi > slash + 1 && (semi == slash + 1 || char.IsWhiteSpace(s[semi - 1]) || true));\n// simplest check: everything after subtype must start with ';' (after optional LWS)","typeGuard":null,"tryCatchPattern":"try { var ct = new ContentType(value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"semicolon\"))\n{ value = value.Replace(\" \", \"; \"); /* or fail fast */ }","preventionTips":["Always use ';' as the parameter separator in OPC content types, never space or '&'.","Format as 'type/subType; name=value; name2=value2'."],"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"}