{"record":{"id":"6a7f821ba21292a9","repo":"tui-cs/Terminal.Gui","slug":"unexpected-color-name-colorstring","errorCode":null,"errorMessage":"Unexpected color name: {colorString}.","messagePattern":"Unexpected color name: (.+?)\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/ColorJsonConverter.cs","lineNumber":52,"sourceCode":"    public override Color Read (ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        // Check if the value is a string\n        if (reader.TokenType == JsonTokenType.String)\n        {\n            // Get the color string\n            ReadOnlySpan<char> colorString = reader.GetString ();\n\n            if (ColorStrings.TryParseNamedColor (colorString, out Color namedColor))\n            {\n                return namedColor;\n            }\n\n            if (Color.TryParse (colorString, null, out Color parsedColor))\n            {\n                return parsedColor;\n            }\n\n            throw new JsonException ($\"Unexpected color name: {colorString}.\");\n        }\n\n        throw new JsonException ($\"Unexpected token when parsing Color: {reader.TokenType}\");\n    }\n\n    public override void Write (Utf8JsonWriter writer, Color value, JsonSerializerOptions options)\n    {\n        writer.WriteStringValue (value.ToString ());\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":63,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/ColorJsonConverter.cs#L34-L63","documentation":"Thrown by ColorJsonConverter.Read: the JSON token was a string, but ColorStrings.TryParseNamedColor and Color.TryParse both failed. The string is neither a W3C named color nor a parseable hex/rgb()/rgba() format. The supported formats are documented on the converter: #RGB, #RRGGBB, #ARGB, #AARRGGBB, rgb(r,g,b), rgb(r,g,b,a), rgba(r,g,b), rgba(r,g,b,a), or a W3C name.","triggerScenarios":"A Color value like \"reed\", \"#GGGGGG\", \"hsl(0,100%,50%)\", \"255,0,0\", or \"red1\" — any string the parser cannot map.","commonSituations":"Typo in a color name; using a CSS format Terminal.Gui does not support (hsl, named-with-suffix like \"darkred\" if not in the W3C set the parser knows); hex string missing the leading #; non-ASCII or quoted-with-smart-quotes.","solutions":["Use a W3C named color (e.g. \"Red\", \"BrightBlue\") or a hex form starting with # (#FF0000).","If you need rgb/rgba, use the exact \"rgb(r,g,b)\" / \"rgba(r,g,b,a)\" syntax with commas.","Confirm the spelling against ColorStrings / the W3C list."],"exampleFix":"// before\n\"Foreground\": \"reed\"\n// after\n\"Foreground\": \"Red\"","handlingStrategy":"validation","validationCode":"string colorStr = reader.GetString ()!;\nif (!ColorStrings.TryParseNamedColor (colorStr, out _)\n    && !Color.TryParse (colorStr, null, out _))\n    throw new FormatException ($\"Unrecognized color: {colorStr}\");","typeGuard":"static bool IsValidColorString (string s) =>\n    ColorStrings.TryParseNamedColor (s, out _) || Color.TryParse (s, null, out _);","tryCatchPattern":"try { ConfigurationManager.Apply (); }\ncatch (JsonException ex) when (ex.Message.Contains (\"Unexpected color name\"))\n{ /* correct the color string */ }","preventionTips":["Restrict config color values to W3C names or #RRGGBB.","Run a color-name validator over config before Load."],"tags":["configuration","json","theming","color"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}