dotnet/wpf · error · ArgumentException

SR.InvalidParameterValue

Error message

SR.InvalidParameterValue

What it means

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.

Solutions

  1. Close the quoted string: append the missing '"'.
  2. Fix escaping — use '\\"' for literal quotes so the closing quote is not treated as escaped.
  3. Use an unquoted token value if quoting is unnecessary.

Example fix

// before
var ct = new ContentType("text/plain; title=\"hello");
// after
var ct = new ContentType("text/plain; title=\"hello\"");
Defensive patterns

Strategy: validation

Validate before calling

public static bool QuotedValuesClosed(string s)
{
    int inQuotes = 0;
    for (int i = 0; i < s.Length; i++)
    {
        if (s[i] == '\\') { i++; continue; }
        if (s[i] == '"') inQuotes ^= 1;
    }
    return inQuotes == 0;
}

Try / catch

try { var ct = new ContentType(value); }
catch (ArgumentException ex) when (ex.Message.Contains("value"))
{ /* fix quoting: ensure balanced, unescaped closing quote */ }

Prevention

When it happens

Trigger: new ContentType("text/plain; title=\"hello") — opening quote never closed; also an escaped quote ('\"') consuming the intended closing quote so no terminator remains.

Common situations: Hand-built quoted values, escaping bugs where backslashes ate the closing quote, truncation of long values in generated files.

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/0ea925e477fe2b37. Report an issue: GitHub.

Appendix: source

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

                    //If there is no linear white space found we treat the entire remaining string as 
                    //parameter value.
                    length = s.Length;
                }
            }
            else
            {
                //if the parameter value starts with a '"' then, we need to look for the
                //pairing '"' that is not preceded by a "\" ["\" is used to escape the '"']
                bool found = false;
                length = startIndex;

                while (!found)
                {
                    int startingLength = ++length;
                    length = s.Slice(startingLength).IndexOf('"');

                    if (length == -1)
                        throw new ArgumentException(SR.InvalidParameterValue);
                    length += startingLength; // IndexOf result is based on slicing from startingLength

                    if (s[length - 1] != '\\')
                    {
                        found = true;
                        length++;
                    }
                }
            }
            return length - startIndex;
        }

        /// <summary>
        /// Validating the given token
        /// The following checks are being made - 
        /// 1. If all the characters in the token are either ASCII letter or digit.
        /// 2. If all the characters in the token are either from the remaining allowed character set.
        /// </summary>

View on GitHub (pinned to 81131a70a4)