dotnet/wpf · error · ArgumentException

SR.ExpectingParameterValuePairs

Error message

SR.ExpectingParameterValuePairs

What it means

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).

Solutions

  1. Remove trailing semicolons: value.TrimEnd(';') (then re-trim whitespace).
  2. Join parameters with ';' without appending one at the end: string.Join(";", parts).
  3. Reject/repair inputs where ';' is the final character before construction.

Example fix

// before
var ct = new ContentType("text/plain;");
// after
var ct = new ContentType("text/plain".TrimEnd(';')); // or fix the value to "text/plain"
Defensive patterns

Strategy: validation

Validate before calling

public static string RemoveTrailingSemicolon(string s) =>
    s.TrimEnd().TrimEnd(';').TrimEnd();

Try / catch

try { var ct = new ContentType(value); }
catch (ArgumentException ex) when (ex.Message.Contains("parameter"))
{ value = RemoveTrailingSemicolon(value); }

Prevention

When it happens

Trigger: new ContentType("text/plain;") or "text/plain; charset=utf8;" — a dangling semicolon at the end of the content type.

Common situations: String building with a loop that appends ';' after the last parameter, copy-paste from lists of parameters, template joins with wrong separator logic.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/864885f4b6affc84. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs:440

        /// Parse the individual parameter=value strings
        /// </summary>
        /// <param name="parameterAndValue">This string has the parameter and value pair of the form
        /// parameter=value</param>
        /// <exception cref="ArgumentException">If the string does not have the required "="</exception>
        private void ParseParameterAndValue(ReadOnlySpan<char> parameterAndValue)
        {
            while (!parameterAndValue.IsEmpty)
            {
                //At this point the first character MUST be a semi-colon
                //First time through this test is serving more as an assert.
                if (parameterAndValue[0] != _semicolonSeparator)
                    throw new ArgumentException(SR.ExpectingSemicolon);

                //At this point if we have just one semicolon, then its an error.
                //Also, there can be no trailing LWS characters, as we already checked for that
                //in the constructor.
                if (parameterAndValue.Length == 1)
                    throw new ArgumentException(SR.ExpectingParameterValuePairs);

                //Removing the leading ; from the string
                parameterAndValue = parameterAndValue.Slice(1);

                //okay to trim start as there can be spaces before the begining
                //of the parameter name.
                parameterAndValue = parameterAndValue.TrimStart(_linearWhiteSpaceChars);

                int equalSignIndex = parameterAndValue.IndexOf(_equalSeparator);

                if (equalSignIndex <= 0 || equalSignIndex == (parameterAndValue.Length - 1))
                    throw new ArgumentException(SR.InvalidParameterValuePair);

                int parameterStartIndex = equalSignIndex + 1;

                //Get length of the parameter value
                int parameterValueLength = GetLengthOfParameterValue(parameterAndValue, parameterStartIndex);

View on GitHub (pinned to 81131a70a4)