{"record":{"id":"ae8a1d8448e81e74","repo":"unoplatform/uno","slug":"failed-to-parse-color-code-colorcode","errorCode":null,"errorMessage":"Failed to parse color code: #{colorCode}","messagePattern":"Failed to parse color code: #(.+?)","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/Utils/ColorCodeParser.cs","lineNumber":56,"sourceCode":"\t\t\t\tb = Convert.ToByte(new string(colorCode[4], 2), 16);\n\t\t\t}\n\t\t\telse if (colorCode.Length == 7)\n\t\t\t{\n\t\t\t\ta = 0xFF;\n\t\t\t\tr = Convert.ToByte(colorCode.Substring(1, 2), 16);\n\t\t\t\tg = Convert.ToByte(colorCode.Substring(3, 2), 16);\n\t\t\t\tb = Convert.ToByte(colorCode.Substring(5, 2), 16);\n\t\t\t}\n\t\t\telse if (colorCode.Length == 9)\n\t\t\t{\n\t\t\t\ta = Convert.ToByte(colorCode.Substring(1, 2), 16);\n\t\t\t\tr = Convert.ToByte(colorCode.Substring(3, 2), 16);\n\t\t\t\tg = Convert.ToByte(colorCode.Substring(5, 2), 16);\n\t\t\t\tb = Convert.ToByte(colorCode.Substring(7, 2), 16);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tthrow new FormatException($\"Failed to parse color code: #{colorCode}\");\n\t\t\t}\n\n\t\t\treturn $\"{a}, {r}, {g}, {b}\";\n\t\t}\n\t}\n}\n","sourceCodeStart":38,"sourceCodeEnd":63,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/Utils/ColorCodeParser.cs#L38-L63","documentation":"After the '#', ParseColorCode accepts only specific lengths: 4 (#RGB, alpha forced to 0xFF), 7 (#RRGGBB, alpha 0xFF), and 9 (#AARRGGBB). Any other length — including #RRGGBBAA (8) or stray digits — falls through to a FormatException reporting the offending value.","triggerScenarios":"A hex color literal whose length (excluding the '#') is not 3, 6, or 8 — e.g. '#FF00' (5 total), '#12345' (6 total), '#1234567' (8 total), '#123456789' (10 total).","commonSituations":"Typo in a XAML color such as a dropped/doubled digit; pasting an 8-digit RGBA when ARGB was expected; truncation during copy/paste.","solutions":["Use a supported form: #RGB, #RRGGBB, or #AARRGGBB.","Double-check the digit count and that alpha precedes RGB (AARRGGBB) for 9-char literals.","Validate the literal length before generation."],"exampleFix":"<!-- before -->\n<SolidColorBrush Color=\"#FF00000\" />\n<!-- after -->\n<SolidColorBrush Color=\"#FFFF0000\" />","handlingStrategy":"validation","validationCode":"static bool IsValidHexColor(string s)\n    => s != null && s.StartsWith(\"#\") && (s.Length == 4 || s.Length == 7 || s.Length == 9)\n       && s.Skip(1).All(c => \"0123456789aAbBcCdDeEfF\".IndexOf(c) >= 0);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only #RGB (4), #RRGGBB (7), or #AARRGGBB (9) forms.","For 8-channel data remember Uno expects AARRGGBB, not RGBA."],"tags":["xaml","color","parser","format"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}