dotnet/wpf · error · ArgumentException
SR.InvalidParameterValuePair
Error message
SR.InvalidParameterValuePair
What it means
Each parameter must be of the form name=value. ParseParameterAndValue locates '=' and throws ArgumentException(SR.InvalidParameterValuePair) if there is no '=', the '=' is the first character (empty name), or it is the last character (empty value).
Solutions
- Ensure every parameter has both a non-empty name and value: name=value.
- Validate each parameter with: int i = p.IndexOf('='); if (i <= 0 || i == p.Length-1) reject.
- Quote values containing special characters, e.g. charset="utf-8" where grammar requires.
Example fix
// before
var ct = new ContentType("text/plain; charset");
// after
var ct = new ContentType("text/plain; charset=utf-8"); Defensive patterns
Strategy: validation
Validate before calling
public static bool ParametersWellFormed(string s)
{
foreach (var p in s.Split(';', StringSplitOptions.RemoveEmptyEntries).Skip(1))
{
var t = p.Trim();
int i = t.IndexOf('=');
if (i <= 0 || i == t.Length - 1) return false;
}
return true;
} Try / catch
try { var ct = new ContentType(value); }
catch (ArgumentException ex) when (ex.Message.Contains("parameter"))
{ /* reject input or repair the name=value pair */ } Prevention
- Validate each parameter as non-empty name=value before construction.
- Never emit key-only parameters; drop parameters whose value is missing.
When it happens
Trigger: new ContentType("text/plain; charset") (no '='), "text/plain; =utf8" (empty name), "text/plain; charset=" (empty value).
Common situations: Truncated strings from logs/config, key-only parameters copied from other formats, accidental deletion of a value during editing.
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
- SR.ExpectingParameterValuePairs
- SR.ExpectingSemicolon
- SR.InvalidParameterValue
- SR.InvalidTypeSubType
- throw new…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/9e79a869cf85c101.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs:452
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);
EnsureParameterDictionary();
_parameterDictionary.Add(
ValidateToken(parameterAndValue.Slice(0, equalSignIndex).ToString()),
ValidateQuotedStringOrToken(parameterAndValue.Slice(parameterStartIndex, parameterValueLength).ToString()));
parameterAndValue = parameterAndValue.Slice(parameterStartIndex + parameterValueLength).TrimStart(_linearWhiteSpaceChars);
}
}
/// <summary>
/// This method returns the length of the first parameter value in the input string.View on GitHub (pinned to 81131a70a4)