{"record":{"id":"314b6341cc40d6e2","repo":"SixLabors/ImageSharp","slug":"input-string-is-not-in-the-correct-format","errorCode":null,"errorMessage":"Input string is not in the correct format.","messagePattern":"Input string is not in the correct format\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Color/Color.cs","lineNumber":301,"sourceCode":"    /// <param name=\"input\">\n    /// The name of the color or the hexadecimal representation of the combined color components.\n    /// </param>\n    /// <param name=\"format\">\n    /// The format of the hexadecimal string to parse, if applicable. Defaults to <see cref=\"ColorHexFormat.Rgba\"/>.\n    /// </param>\n    /// <returns>\n    /// The <see cref=\"Color\"/> equivalent of the input string.\n    /// </returns>\n    /// <exception cref=\"ArgumentException\">\n    /// Thrown when the <paramref name=\"input\"/> is not in the correct format.\n    /// </exception>\n    public static Color Parse(string input, ColorHexFormat format = ColorHexFormat.Rgba)\n    {\n        Guard.NotNull(input, nameof(input));\n\n        if (!TryParse(input, out Color color, format))\n        {\n            throw new ArgumentException(\"Input string is not in the correct format.\", nameof(input));\n        }\n\n        return color;\n    }\n\n    /// <summary>\n    /// Tries to create a new instance of the <see cref=\"Color\"/> struct from the given input string.\n    /// </summary>\n    /// <param name=\"input\">\n    /// The name of the color or the hexadecimal representation of the combined color components.\n    /// </param>\n    /// <param name=\"result\">\n    /// When this method returns, contains the <see cref=\"Color\"/> equivalent of the input string.\n    /// </param>\n    /// <param name=\"format\">\n    /// The format of the hexadecimal string to parse, if applicable. Defaults to <see cref=\"ColorHexFormat.Rgba\"/>.\n    /// </param>\n    /// <returns>","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Color/Color.cs#L283-L319","documentation":"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.'","triggerScenarios":"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.","commonSituations":"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.","solutions":["Validate with Color.TryParse(input, out Color c, format) before calling Parse","Use exact documented color names or valid hex forms","Trim whitespace and normalize casing of named colors","Verify the ColorHexFormat argument matches how your input encodes alpha"],"exampleFix":"// before\nvar color = Color.Parse(input); // input = \"blu\"\n// after\nif (!Color.TryParse(input, out var color)) { /* handle invalid input */ }","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(input) || !(Color.TryParse(input, out _, format)))\n    throw new ArgumentException($\"Invalid color: {input}\");","typeGuard":null,"tryCatchPattern":"try { var c = Color.Parse(input); }\ncatch (ArgumentException ex) { logger.LogError(ex, \"Bad color string: {Input}\", input); }","preventionTips":["Use Color.TryParse for any user/config-supplied color string","Normalize casing/whitespace before parsing","Match the input encoding to the ColorHexFormat argument"],"tags":["color","parsing","invalid-argument-format"],"backgroundTag":"invalid-argument-format","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}