{"record":{"id":"d7afb0c51b8ea045","repo":"unoplatform/uno","slug":"color-code-must-start-with","errorCode":null,"errorMessage":"Color code must start with #","messagePattern":"Color code must start with #","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/Utils/ColorCodeParser.cs","lineNumber":18,"sourceCode":"﻿#nullable enable\n\nusing System;\n\nnamespace Uno.UI.SourceGenerators.XamlGenerator.Utils\n{\n\tinternal static class ColorCodeParser\n\t{\n\t\tpublic static string ParseColorCode(string colorCode)\n\t\t{\n\t\t\tif (colorCode == null)\n\t\t\t{\n\t\t\t\tthrow new ArgumentNullException(nameof(colorCode));\n\t\t\t}\n\n\t\t\tif (!colorCode.StartsWith(\"#\", StringComparison.Ordinal))\n\t\t\t{\n\t\t\t\tthrow new FormatException(\"Color code must start with #\");\n\t\t\t}\n\n\t\t\tbyte a;\n\t\t\tbyte r;\n\t\t\tbyte g;\n\t\t\tbyte b;\n\n\t\t\tif (colorCode.Length == 4)\n\t\t\t{\n\t\t\t\ta = 0xFF;\n\t\t\t\tr = Convert.ToByte(new string(colorCode[1], 2), 16);\n\t\t\t\tg = Convert.ToByte(new string(colorCode[2], 2), 16);\n\t\t\t\tb = Convert.ToByte(new string(colorCode[3], 2), 16);\n\t\t\t}\n\t\t\telse if (colorCode.Length == 5)\n\t\t\t{\n\t\t\t\ta = Convert.ToByte(new string(colorCode[1], 2), 16);\n\t\t\t\tr = Convert.ToByte(new string(colorCode[2], 2), 16);","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/Utils/ColorCodeParser.cs#L1-L36","documentation":"ParseColorCode parses XAML hex color literals and requires the value to begin with '#'. Any input lacking the leading '#' throws FormatException. This runs during XAML code generation whenever a color attribute/resource resolves to a hex string.","triggerScenarios":"A color value passed to the parser does not start with '#', e.g. a bare hex 'FF0000', a named color like 'Red' routed where hex is expected, or an empty/garbage string.","commonSituations":"Hand-edited XAML with a Color attribute missing the '#'; a resource/binding that evaluates to a non-hex string at generation time.","solutions":["Prefix the color value with '#', e.g. Color=\"#FFFF0000\".","Use a XAML-recognized named color or a {ThemeResource}/{StaticResource} brush instead of a raw hex string where appropriate.","Validate color literals before they reach the generator."],"exampleFix":"<!-- before -->\n<SolidColorBrush Color=\"FF0000\" />\n<!-- after -->\n<SolidColorBrush Color=\"#FFFF0000\" />","handlingStrategy":"validation","validationCode":"static bool IsValidHexColor(string s) => !string.IsNullOrEmpty(s) && s.StartsWith(\"#\", StringComparison.Ordinal);\n// reject color literals before they reach the generator if !IsValidHexColor(value)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always prefix XAML hex colors with '#'.","Use named colors or {ThemeResource}/{StaticResource} brushes for theme colors."],"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"}