dotnet/wpf · error · ArgumentException

SR.InvalidToken

Error message

SR.InvalidToken

What it means

ContentType.ValidateToken throws this ArgumentException when a MIME token (type, subtype, parameter or value) is empty or contains characters outside the allowed set (ASCII letters/digits and a restricted set of RFC-compliant punctuation, with quoting for token strings). It is a shared grammar validator used while parsing ContentType strings.

Solutions

  1. Ensure MIME/ContentType tokens (type, subtype, parameter names and values) contain only allowed RFC-compliant characters
  2. Quote parameter values that contain special characters per the content-type grammar
  3. Catch ArgumentException when parsing untrusted Content-Type strings
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs:537 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

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

                    }
                }
            }
            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>
        /// <param name="token">string token</param>
        /// <returns>validated string token</returns>
        /// <exception cref="ArgumentException">If the token is Empty</exception>
        private static string ValidateToken(string token)
        {
            if (string.IsNullOrEmpty(token))
                throw new ArgumentException(SR.InvalidToken);

            for (int i = 0; i < token.Length; i++)
            {
                if (IsAsciiLetterOrDigit(token[i]))
                    continue;
                else
                    if (IsAllowedCharacter(token[i]))
                        continue;
                    else
                        throw new ArgumentException(SR.InvalidToken);
            }

            return token;
        }

        /// <summary>
        /// Validating if the value of a parameter is either a valid token or a 
        /// valid quoted string

View on GitHub (pinned to 81131a70a4)