{"record":{"id":"fb1193283ba89766","repo":"tui-cs/Terminal.Gui","slug":"color-hex-string-hexstring-was-not-in-a-supporte","errorCode":null,"errorMessage":"Color hex string {hexString} was not in a supported format","messagePattern":"Color hex string (.+?) was not in a supported format","errorType":"validation","errorClass":"ColorParseException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Drawing/Color/Color.Formatting.cs","lineNumber":327,"sourceCode":"                        byte.Parse ([r1Char, r2Char], NumberStyles.HexNumber),\n                        byte.Parse ([g1Char, g2Char], NumberStyles.HexNumber),\n                        byte.Parse ([b1Char, b2Char], NumberStyles.HexNumber)\n                    ),\n\n                // #AARRGGBB\n                [\n                    '#', var a1Char, var a2Char,\n                    var r1Char, var r2Char,\n                    var g1Char, var g2Char,\n                    var b1Char, var b2Char\n                ] chars when chars [1..].IsAllAsciiHexDigits () =>\n                    new Color (\n                        byte.Parse ([r1Char, r2Char], NumberStyles.HexNumber),\n                        byte.Parse ([g1Char, g2Char], NumberStyles.HexNumber),\n                        byte.Parse ([b1Char, b2Char], NumberStyles.HexNumber),\n                        byte.Parse ([a1Char, a2Char], NumberStyles.HexNumber)\n                    ),\n                _ => throw new ColorParseException (\n                        in hexString,\n                        $\"Color hex string {hexString} was not in a supported format\",\n                        in hexString\n                    )\n            },\n\n            // rgb(r,g,b) or rgb(r,g,b,a)\n            ['r', 'g', 'b', '(', .., ')'] => ParseRgbaFormat (in text, 4),\n\n            // rgba(r,g,b,a) or rgba(r,g,b)\n            ['r', 'g', 'b', 'a', '(', .., ')'] => ParseRgbaFormat (in text, 5),\n            // Attempt named colors\n            { } when char.IsLetter (text [0]) && ColorStrings.TryParseNamedColor (text, out Color color) => color,\n            // Any other input\n            _ => throw new ColorParseException (in text, \"Text did not match any expected format.\", in text, [])\n        };\n\n        [Pure]","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drawing/Color/Color.Formatting.cs#L309-L345","documentation":"Thrown by the hex sub-switch of Color.Parse when the input begins with '#' but does not match #RGB, #ARGB, #RRGGBB, or #AARRGGBB, or when its characters after '#' are not all valid ASCII hex digits. The message interpolates the offending hexString so you can see exactly what failed. It is a ColorParseException (FormatException).","triggerScenarios":"Passing '#12' (wrong length), '#GGG' or '#12GH56' (non-hex digits), '#12345' (5 chars, no matching pattern), or '#RRGGBBAA' (the library only accepts alpha-first #AARRGGBB, not alpha-last).","commonSituations":"Confusing #RRGGBBAA (alpha last) with the supported #AARRGGBB (alpha first), copying a CSS hex with trailing alpha in the wrong position, typos, or non-hex characters sneaking into the string.","solutions":["Verify the string is exactly 4, 5, 7, or 9 chars and that chars[1..] are hex digits before parsing.","If you have #RRGGBBAA, reorder alpha to the front (#AARRGGBB) before calling Parse.","Use Color.TryParse to gracefully handle malformed hex."],"exampleFix":"// before (wrong: alpha last is unsupported)\nColor c = Color.Parse(\"#FF8800AA\");\n\n// after (alpha first, or drop alpha)\nColor c = Color.Parse(\"#AAFF8800\");","handlingStrategy":"validation","validationCode":"ReadOnlySpan<char> s = text.AsSpan();\nbool ok = s.Length is 4 or 5 or 7 or 9 && s[0]=='#' && s[1..].IsAllAsciiHexDigits();","typeGuard":"static bool IsValidHexColor(ReadOnlySpan<char> s) =>\n    s.Length is 4 or 5 or 7 or 9 && s[0]=='#' && s[1..].IsAllAsciiHexDigits();","tryCatchPattern":"try { c = Color.Parse(hex.AsSpan()); } catch (ColorParseException ex) { /* inspect ex.ColorString */ c = fallback; }","preventionTips":["Remember only #RGB, #ARGB, #RRGGBB, #AARRGGBB are supported.","Alpha must be first (#AARRGGBB), not last.","Validate hex length and IsAllAsciiHexDigits before parsing."],"tags":["color","parsing","hex","alpha-channel","format-exception"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}