SixLabors/ImageSharp · error · ArgumentException

Input string is not in the correct format.

Error message

Input string is not in the correct format.

What it means

Color.Parse is the general string-parsing entry point (hex and named colors). When TryParse fails to recognize the input in the requested ColorHexFormat, it throws ArgumentException naming the 'input' parameter with the message 'Input string is not in the correct format.'

Solutions

  1. Validate with Color.TryParse(input, out Color c, format) before calling Parse
  2. Use exact documented color names or valid hex forms
  3. Trim whitespace and normalize casing of named colors
  4. Verify the ColorHexFormat argument matches how your input encodes alpha

Example fix

// before
var color = Color.Parse(input); // input = "blu"
// after
if (!Color.TryParse(input, out var color)) { /* handle invalid input */ }
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(input) || !(Color.TryParse(input, out _, format)))
    throw new ArgumentException($"Invalid color: {input}");

Try / catch

try { var c = Color.Parse(input); }
catch (ArgumentException ex) { logger.LogError(ex, "Bad color string: {Input}", input); }

Prevention

When it happens

Trigger: Calling Color.Parse with an unrecognized color name ('redd'), malformed hex, empty-after-guard strings that fail parsing, or input whose format does not match the supplied ColorHexFormat.

Common situations: Parsing user-supplied color strings from forms/CLI/config; locale or case variations of color names; switching from ParseHex to Parse with a hex string in a format the parser rejects; localized color names.

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 SixLabors/ImageSharp@59ce6af6fc (2026-09-13). Data as JSON: /api/errors/314b6341cc40d6e2. Report an issue: GitHub.

Appendix: source

Thrown at src/ImageSharp/Color/Color.cs:301

    /// <param name="input">
    /// The name of the color or the hexadecimal representation of the combined color components.
    /// </param>
    /// <param name="format">
    /// The format of the hexadecimal string to parse, if applicable. Defaults to <see cref="ColorHexFormat.Rgba"/>.
    /// </param>
    /// <returns>
    /// The <see cref="Color"/> equivalent of the input string.
    /// </returns>
    /// <exception cref="ArgumentException">
    /// Thrown when the <paramref name="input"/> is not in the correct format.
    /// </exception>
    public static Color Parse(string input, ColorHexFormat format = ColorHexFormat.Rgba)
    {
        Guard.NotNull(input, nameof(input));

        if (!TryParse(input, out Color color, format))
        {
            throw new ArgumentException("Input string is not in the correct format.", nameof(input));
        }

        return color;
    }

    /// <summary>
    /// Tries to create a new instance of the <see cref="Color"/> struct from the given input string.
    /// </summary>
    /// <param name="input">
    /// The name of the color or the hexadecimal representation of the combined color components.
    /// </param>
    /// <param name="result">
    /// When this method returns, contains the <see cref="Color"/> equivalent of the input string.
    /// </param>
    /// <param name="format">
    /// The format of the hexadecimal string to parse, if applicable. Defaults to <see cref="ColorHexFormat.Rgba"/>.
    /// </param>
    /// <returns>

View on GitHub (pinned to 59ce6af6fc)