{"record":{"id":"e58d988feda429e7","repo":"dotnet/wpf","slug":"sr-format-sr-invalidstringcornerradius-s","errorCode":null,"errorMessage":"SR.Format(SR.InvalidStringCornerRadius, s)","messagePattern":"SR\\.Format\\(SR\\.InvalidStringCornerRadius, s\\)","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadiusConverter.cs","lineNumber":184,"sourceCode":"                    break;\n                }\n\n                radii[i] = double.Parse(th.GetCurrentToken(), cultureInfo);\n                i++;\n            }\n\n            // We have a reasonable interpreation for one value (all four edges)\n            // and four values (left, top, right, bottom).\n            switch (i)\n            {\n                case 1:\n                    return (new CornerRadius(radii[0]));\n\n                case 4:\n                    return (new CornerRadius(radii[0], radii[1], radii[2], radii[3]));\n            }\n\n            throw new FormatException(SR.Format(SR.InvalidStringCornerRadius, s));\n        }\n        #endregion\n    }\n}\n","sourceCodeStart":166,"sourceCodeEnd":189,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadiusConverter.cs#L166-L189","documentation":"CornerRadiusConverter's FromString parser accepts only strings that tokenize into 1 or 4 numeric values (uniform radius or TopLeft/TopRight/BottomRight/BottomLeft). Any other form — wrong token count or non-numeric tokens that escape the DoubleParser — results in a FormatException built from SR.InvalidStringCornerRadius including the offending string.","triggerScenarios":"ConvertFrom(\"1 2 3\") (wrong number of values), ConvertFrom(\"abc\") or ConvertFrom(\"10,20,x,40\") (non-numeric tokens); loading malformed XAML like CornerRadius=\"1,2,3\".","commonSituations":"Hand-edited XAML/ResourceDictionary values, user-entered input in property grids, config files with incorrectly formatted radius strings, culture-sensitive decimal separators.","solutions":["Supply either one number ('8') or four comma/space-separated numbers ('8,8,8,8').","Pre-validate with a split-and-double.TryParse loop before calling the converter.","Catch FormatException around ConvertFrom when parsing user input and show a corrective message."],"exampleFix":"// before\nvar cr = (CornerRadius)converter.ConvertFrom(null, culture, \"1 2 3\");\n// after\nvar cr = (CornerRadius)converter.ConvertFrom(null, culture, \"1 2 3 4\"); // or \"1\"","handlingStrategy":"validation","validationCode":"static bool IsValidCornerRadiusString(string s, CultureInfo ci)\n{\n    if (string.IsNullOrWhiteSpace(s)) return false;\n    var parts = s.Split(new[]{' ', ','}, StringSplitOptions.RemoveEmptyEntries);\n    if (parts.Length != 1 && parts.Length != 4) return false;\n    return parts.All(p => double.TryParse(p, NumberStyles.Float, ci, out _));\n}","typeGuard":null,"tryCatchPattern":"try { cr = (CornerRadius)converter.ConvertFrom(null, culture, s); } catch (FormatException ex) { Log.Warn($\"Invalid CornerRadius '{s}': use 'N' or 'N,N,N,N'.\"); cr = new CornerRadius(0); }","preventionTips":["Only write radius strings with 1 or 4 comma/space-separated numbers.","Use InvariantCulture when serializing/parsing to avoid decimal-separator issues.","Validate user-entered property values before invoking the converter."],"tags":["wpf","typeconverter","format","parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}