{"record":{"id":"f7f4bc01dbe9a004","repo":"tui-cs/Terminal.Gui","slug":"text-did-not-match-any-expected-format","errorCode":null,"errorMessage":"Text did not match any expected format.","messagePattern":"Text did not match any expected format\\.","errorType":"validation","errorClass":"ColorParseException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Drawing/Color/Color.Formatting.cs","lineNumber":342,"sourceCode":"                        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]\n        [SkipLocalsInit]\n        static Color ParseRgbaFormat (in ReadOnlySpan<char> originalString, in int startIndex)\n        {\n            ReadOnlySpan<char> valuesSubstring = originalString [startIndex..^1];\n            Span<Range> valueRanges = stackalloc Range [4];\n\n            int rangeCount = valuesSubstring.Split (\n                                                    valueRanges,\n                                                    ',',\n                                                    StringSplitOptions.RemoveEmptyEntries\n                                                    | StringSplitOptions.TrimEntries\n                                                   );\n\n            switch (rangeCount)\n            {","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drawing/Color/Color.Formatting.cs#L324-L360","documentation":"The final fallthrough of Color.Parse: the input did not start with '#', did not match rgb(...)/rgba(...), and was not a recognized named color. Because every prior pattern was exhausted, the parser gives up with this ColorParseException (FormatException). The empty badValueName array indicates no single component is to blame.","triggerScenarios":"Passing an unrecognized color name (e.g. \"banana\"), an unsupported function format like \"hsl(0,0%,100%)\", an uppercase \"RGB(1,2,3)\" (the pattern is case-sensitive lowercase), or a stray symbol like \"@red\".","commonSituations":"Misspelled named colors, CSS hsl/hwb syntax that Terminal.Gui does not support, uppercase function names from user input, or locale-specific color names.","solutions":["Use Color.TryParse and validate the name against ColorName16 values or ColorStrings.TryParseNamedColor first.","Convert unsupported formats (hsl, uppercase RGB) to a supported form (#RRGGBB or lowercase rgb()) before parsing.","Check char.IsLetter(text[0]) then call ColorStrings.TryParseNamedColor to confirm the name is valid."],"exampleFix":"// before\nColor c = Color.Parse(userColorName);\n\n// after\nif (!Color.TryParse(userColorName, null, out Color c))\n{\n    throw new InvalidOperationException($\"Unknown color '{userColorName}'.\");\n}","handlingStrategy":"validation","validationCode":"if (!Color.TryParse(userColor, null, out Color c)) return fallbackColor;","typeGuard":"static bool IsKnownColorName(string s) =>\n    s.Length > 0 && char.IsLetter(s[0]) && ColorStrings.TryParseNamedColor(s, out _);","tryCatchPattern":"try { c = Color.Parse(s); } catch (ColorParseException) { c = fallback; }","preventionTips":["rgb()/rgba() must be lowercase in the function name.","hsl/hwb and other CSS functions are unsupported; convert first.","Validate named colors via ColorStrings.TryParseNamedColor."],"tags":["color","parsing","named-color","format-exception"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}