{"record":{"id":"58231b1059d1dfb6","repo":"unoplatform/uno","slug":"invalid-value-part-unable-to-parse","errorCode":null,"errorMessage":"Invalid value '{part}', unable to parse.","messagePattern":"Invalid value '(.+?)', unable to parse\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/StarStackPanel.cs","lineNumber":552,"sourceCode":"\n\t\tprivate static GridLength[] ParseGridLength(string s)\n\t\t{\n\t\t\tvar parts = s.Split(new[] { ',' });\n\n\t\t\tvar result = new List<GridLength>(parts.Length);\n\n\t\t\tforeach (var part in parts)\n\t\t\t{\n\t\t\t\tif (string.IsNullOrEmpty(part))\n\t\t\t\t{\n\t\t\t\t\tresult.Add(GridLengthHelper2.FromValueAndType(0, GridUnitType.Auto));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tvar match = GridLengthParsingRegex.Match(part);\n\t\t\t\tif (!match.Success)\n\t\t\t\t{\n\t\t\t\t\tthrow new InvalidOperationException(\"Invalid value '\" + part + \"', unable to parse.\");\n\t\t\t\t}\n\n\t\t\t\tvar autoGroup = match.Groups[\"auto\"];\n\t\t\t\tif (autoGroup.Success)\n\t\t\t\t{\n\t\t\t\t\tresult.Add(GridLengthHelper2.FromValueAndType(0, GridUnitType.Auto));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tvar starsGroup = match.Groups[\"stars\"];\n\t\t\t\tif (starsGroup.Success)\n\t\t\t\t{\n\t\t\t\t\tvar value =\n\t\t\t\t\t\t!string.IsNullOrWhiteSpace(starsGroup.Value)\n\t\t\t\t\t\t\t? double.Parse(starsGroup.Value, CultureInfo.InvariantCulture)\n\t\t\t\t\t\t\t: 1;\n\t\t\t\t\tresult.Add(GridLengthHelper2.FromValueAndType(value, GridUnitType.Star));\n\t\t\t\t\tcontinue;","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/StarStackPanel.cs#L534-L570","documentation":"Thrown by the StarStackPanel test-helper control when parsing a comma-separated list of GridLength segments (e.g. a ColumnDefinitions/RowDefinitions string). Each non-empty segment is matched against GridLengthParsingRegex, which accepts forms like 'Auto', '*', '2*', or a fixed pixel value. If a segment is neither empty nor matched by the regex, the parser cannot produce a GridLength and aborts. This is sample/test infrastructure, not shipping framework API.","triggerScenarios":"Calling the parsing path of StarStackPanel (or a test/sample driving it) with a string that contains a token the regex does not recognize, such as '1*, foo, Auto' or a value with stray characters/units like '100px'.","commonSituations":"Typos in a manually authored definitions string in a sample page, copy-pasting CSS-style units ('px','em') into a GridLength list, locale-specific decimal separators ('1,5*' under comma cultures being split early), or trailing/leading whitespace combined with an invalid token.","solutions":["Inspect the exact '{part}' value in the message and correct it to a valid GridLength form: 'Auto', '*', 'N*' (e.g. '2*'), or a plain number for pixels.","Sanitize the input string before parsing: trim whitespace and split on a culture-invariant separator so decimal values are not mis-split.","If extending StarStackPanel, broaden GridLengthParsingRegex to accept the additional units you need, or pre-validate each segment and report all bad parts at once.","Reproduce with a unit test feeding the failing string to isolate which token breaks the regex."],"exampleFix":"// before\nStarStackPanel.SetValues(\"1*, 100px, Auto\"); // '100px' is not a valid GridLength\n\n// after\nStarStackPanel.SetValues(\"1*, 100, Auto\");","handlingStrategy":"validation","validationCode":"static readonly Regex _valid = new Regex(@\"^\\s*(auto|\\d*\\.?\\d*\\*?|\\d+(\\.\\d+)?)\\s*$\", RegexOptions.IgnoreCase);\nstatic IEnumerable<string> FindBadParts(string input) => input.Split(',').Where(p => !string.IsNullOrWhiteSpace(p) && !_valid.IsMatch(p.Trim()));","typeGuard":"static bool IsValidGridLengthString(string s) => string.IsNullOrWhiteSpace(s) || s.Split(',').All(p => p.Trim() == \"\" || _valid.IsMatch(p.Trim()));","tryCatchPattern":"try { panel.SetValues(text); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"unable to parse\")) { log.Warn($\"Bad GridLength input '{text}': {ex.Message}\"); panel.SetValues(SafeDefault); }","preventionTips":["Validate the definitions string with a regex before passing it to StarStackPanel.","Use CultureInfo.InvariantCulture when splitting on decimal separators.","Add a unit test that round-trips canonical GridLength strings through the parser."],"tags":["gridlength","parsing","samples","uitests","regex"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}