AvaloniaUI/Avalonia · error · FormatException
Invalid CornerRadius.
Error message
Invalid CornerRadius.
What it means
Thrown as FormatException by CornerRadius.Parse(string) when the input string cannot be tokenized into 1–4 double values (uniform, top-left/bottom-right, or four-corner). Parse uses an invariant-culture SpanStringTokenizer and the message 'Invalid CornerRadius.' is the constant exceptionMessage.
Source
Thrown at src/Avalonia.Base/CornerRadius.cs:114
using (var tokenizer = new SpanStringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage))
{
if (tokenizer.TryReadDouble(out var a))
{
if (tokenizer.TryReadDouble(out var b))
{
if (tokenizer.TryReadDouble(out var c))
{
return new CornerRadius(a, b, c, tokenizer.ReadDouble());
}
return new CornerRadius(a, b);
}
return new CornerRadius(a);
}
throw new FormatException(exceptionMessage);
}
}
public static bool operator ==(CornerRadius left, CornerRadius right)
{
return left.Equals(right);
}
public static bool operator !=(CornerRadius left, CornerRadius right)
{
return !(left == right);
}
}
}
View on GitHub (pinned to 11c5427268)
Solutions
- Provide a valid CornerRadius string: one value ("5"), two ("5,10"), or four ("5,10,5,10") doubles separated by commas or spaces, using invariant period decimals.
- If the source is locale-dependent, normalize/replace separators before parsing or use the CornerRadius(double) constructors directly.
- Validate with double.TryParse on each token before calling Parse, or wrap Parse in try/catch FormatException.
Example fix
// before
var c = CornerRadius.Parse("1;2"); // throws
// after
var c = CornerRadius.Parse("1,2"); // or new CornerRadius(1, 2) Defensive patterns
Strategy: try-catch
Validate before calling
if (!CornerRadius.TryParseInvariant(s, out var corner))
throw new FormatException($"Invalid CornerRadius: '{s}'"); Try / catch
try { var c = CornerRadius.Parse(s); }
catch (FormatException) { c = default; // or log } Prevention
- Use invariant-culture comma-separated doubles for CornerRadius strings.
- Validate user-supplied strings before Parse.
- Prefer the CornerRadius(double...) constructors in code over string parsing.
When it happens
Trigger: Calling CornerRadius.Parse(s) where s is empty, contains non-numeric text, has too many tokens, or uses the wrong decimal separator for invariant culture (e.g., a comma where a period is expected, or locale-specific formatting). Also thrown when the first token read fails entirely (line 114).
Common situations: XAML or code passes a malformed CornerRadius string like "abc", "1,,2", "1;2", or a locale-formatted value using comma decimals. Binding a CornerRadius from a string source with wrong formatting. Deserialization of CornerRadius from user input.
Related errors
- Not supported format
- No Setter property assigned.
- 'name' may not contain periods.
- Could not convert '{s}' to {typeof(T)}.
- Bad format specifier.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/cd8aa7f99d7b053f.
Report an issue: GitHub.