{"record":{"id":"13b4ce76167a8122","repo":"unoplatform/uno","slug":"the-0-string-passed-in-the-colorstring-argument-13b4ce","errorCode":null,"errorMessage":"The {0} string passed in the colorString argument is not a recognized Color.","messagePattern":"The (.+?) string passed in the colorString argument is not a recognized Color\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/SamplesApp/SamplesApp.Samples/Windows_UI_ViewManagement/TitleBarColorTests.xaml.cs","lineNumber":153,"sourceCode":"\t\t\t\t{\n\t\t\t\t\tvar scR = double.Parse(values[0].Substring(3));\n\t\t\t\t\tvar scG = double.Parse(values[1]);\n\t\t\t\t\tvar scB = double.Parse(values[2]);\n\n\t\t\t\t\treturn Color.FromArgb(255, (byte)(scR * 255), (byte)(scG * 255), (byte)(scB * 255));\n\t\t\t\t}\n\n\t\t\t\tthrow new FormatException(string.Format(\"The {0} string passed in the colorString argument is not a recognized Color format (sc#[scA,]scR,scG,scB).\", colorString));\n\t\t\t}\n\n\t\t\tvar prop = typeof(Colors).GetTypeInfo().GetDeclaredProperty(colorString);\n\n\t\t\tif (prop != null)\n\t\t\t{\n\t\t\t\treturn (Color)prop.GetValue(null);\n\t\t\t}\n\n\t\t\tthrow new FormatException(string.Format(\"The {0} string passed in the colorString argument is not a recognized Color.\", colorString));\n\t\t}\n\n\t}\n}\n","sourceCodeStart":135,"sourceCodeEnd":158,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SamplesApp/SamplesApp.Samples/Windows_UI_ViewManagement/TitleBarColorTests.xaml.cs#L135-L158","documentation":"Final fallback of the TitleBar parser: the string was not a recognized '#' hex length, not a valid 'sc#' form, and reflection on typeof(Colors) found no matching named color property. Anything that survives all earlier branches lands here.","triggerScenarios":"Calling the parser with a bare name that is not a member of Windows.UI.Colors / Microsoft.UI.Colors (e.g. 'HotPink', 'transparent', 'grey' with wrong casing if case-sensitive), or a fully unrecognized token like 'banana' or an empty string.","commonSituations":"Typo in a named color, CSS color names that don't exist in the WinUI Colors type, casing differences, or a non-color string fed in from configuration.","solutions":["Use an exact name of a Colors member (e.g. 'Red', 'DodgerBlue'); check against typeof(Colors).GetProperties() for the valid set.","Normalize casing/trim before the reflection lookup if you want case-insensitive named colors.","Fall back to the hex form (#RRGGBB) which is unambiguous.","Whitelist allowed names in the UI."],"exampleFix":"// before\nvar prop = typeof(Colors).GetTypeInfo().GetDeclaredProperty(colorString);\n// after - case-insensitive lookup with explicit error listing valid names\nvar prop = typeof(Colors).GetTypeInfo().DeclaredProperties\n    .FirstOrDefault(p => string.Equals(p.Name, colorString, StringComparison.OrdinalIgnoreCase));\nif (prop is null)\n{\n    throw new FormatException($\"'{colorString}' is not a known Colors name nor a hex/sc# color.\");\n}","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> KnownColorNames =\n    typeof(Colors).GetTypeInfo().DeclaredProperties.Select(p => p.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);\nstatic bool IsKnownColorName(string s) => s != null && KnownColorNames.Contains(s);","typeGuard":null,"tryCatchPattern":"try { var c = ParseColor(input); }\ncatch (FormatException ex) { _log.Warning($\"Unknown color '{input}'.\"); c = Colors.Transparent; }","preventionTips":["Whitelist recognized Colors names from reflection once.","Prefer hex form for unambiguous input.","Do case-insensitive name lookup if user input is involved."],"tags":["xaml","color","parsing","reflection","samples","validation"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}