{"record":{"id":"62d2a8be827b80d2","repo":"unoplatform/uno","slug":"the-0-string-passed-in-the-colorstring-argument-62d2a8","errorCode":null,"errorMessage":"The {0} string passed in the colorString argument is not a recognized Color format (sc#[scA,]scR,scG,scB).","messagePattern":"The (.+?) string passed in the colorString argument is not a recognized Color format \\(sc#\\[scA,\\]scR,scG,scB\\)\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/SamplesApp/SamplesApp.Samples/Windows_UI_ViewManagement/TitleBarColorTests.xaml.cs","lineNumber":143,"sourceCode":"\t\t\t\t{\n\t\t\t\t\tvar scA = double.Parse(values[0].Substring(3));\n\t\t\t\t\tvar scR = double.Parse(values[1]);\n\t\t\t\t\tvar scG = double.Parse(values[2]);\n\t\t\t\t\tvar scB = double.Parse(values[3]);\n\n\t\t\t\t\treturn Color.FromArgb((byte)(scA * 255), (byte)(scR * 255), (byte)(scG * 255), (byte)(scB * 255));\n\t\t\t\t}\n\n\t\t\t\tif (values.Length == 3)\n\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":125,"sourceCodeEnd":158,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SamplesApp/SamplesApp.Samples/Windows_UI_ViewManagement/TitleBarColorTests.xaml.cs#L125-L158","documentation":"Thrown by the same TitleBar parser when the string starts with 'sc#' (WinUI scRGB double format) but the comma-split does not produce exactly 3 (sc#r,g,b) or 4 (sc#a,r,g,b) values. The parser then has no branch to handle the wrong arity.","triggerScenarios":"Passing 'sc#0.5' (1 value), 'sc#0.5,0.2' (2 values), 'sc#0.1,0.2,0.3,0.4,0.5' (5+ values), or a value with a trailing comma that produces an empty segment count mismatch.","commonSituations":"Confusing the sc# double form with the hex form; using localized decimal separators (',' as decimal) that double.Parse misreads, or supplying RGB without alpha but the components are separated incorrectly.","solutions":["Supply exactly 3 components (sc#R,G,B, each 0..1) or 4 (sc#A,R,G,B).","Ensure the decimal separator is '.' (invariant culture) — double.Parse here uses current culture, so a ',' separator can collide with decimal commas; use double.Parse(values[i], CultureInfo.InvariantCulture) to be safe.","Strip trailing commas and whitespace before splitting.","If the sc# form is not needed, use the plain hex form instead."],"exampleFix":"// before\nvar values = colorString.Split(',');\n// after - split with options and invariant parse\nvar values = colorString.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);\nif (values.Length is not 3 and not 4)\n{\n    throw new FormatException($\"sc# needs 3 or 4 components, got {values.Length} in '{colorString}'.\");\n}\nvar scR = double.Parse(values[0].Substring(3), CultureInfo.InvariantCulture);","handlingStrategy":"validation","validationCode":"static bool TryParseScRgb(string s, out double[] comps)\n{\n    comps = null;\n    if (s == null || s.Length <= 3 || s[0]!='s' || s[1]!='c' || s[2]!='#') return false;\n    var parts = s.Substring(3).Split(',', StringSplitOptions.TrimEntries);\n    if (parts.Length is not 3 and not 4) return false;\n    comps = parts.Select(p => double.Parse(p, CultureInfo.InvariantCulture)).ToArray();\n    return comps.All(d => d is >= 0 and <= 1);\n}","typeGuard":null,"tryCatchPattern":"try { var c = ParseColor(input); }\ncatch (FormatException ex) when (ex.Message.Contains(\"sc#\")) { /* prompt user for valid sc# form */ }","preventionTips":["Use CultureInfo.InvariantCulture when parsing doubles to avoid decimal-separator collisions with the comma separator.","Validate component count (3 or 4) before parsing.","Trim entries and reject empty segments."],"tags":["xaml","color","parsing","scrgb","samples","validation"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}