AvaloniaUI/Avalonia · error · InvalidDataException
Invalid double value
Error message
Invalid double value
What it means
Thrown by ReadDouble when ReadArgument could not extract a valid numeric token from the span. ReadArgument validates an optional leading '-', integer digits, an optional '.', fractional digits, and optional scientific notation; if none of those form a valid number, ReadArgument returns false and ReadDouble throws. This affects every numeric coordinate, size, and angle in the path.
Source
Thrown at src/Avalonia.Base/Media/PathMarkupParser.cs:561
span = span.Slice(1);
switch (c)
{
case '0':
return false;
case '1':
return true;
default:
throw new InvalidDataException("Invalid bool rule");
}
}
private static double ReadDouble(ref ReadOnlySpan<char> span)
{
if (!ReadArgument(ref span, out var doubleValue))
{
throw new InvalidDataException("Invalid double value");
}
return double.Parse(doubleValue.ToString(), CultureInfo.InvariantCulture);
}
private static Size ReadSize(ref ReadOnlySpan<char> span)
{
var width = ReadDouble(ref span);
span = ReadSeparator(span);
var height = ReadDouble(ref span);
return new Size(width, height);
}
private static Point ReadPoint(ref ReadOnlySpan<char> span)
{
var x = ReadDouble(ref span);
span = ReadSeparator(span);
var y = ReadDouble(ref span);View on GitHub (pinned to 11c5427268)
Solutions
- Ensure every numeric argument is a well-formed number using '.' as the decimal separator and invariant culture.
- Remove trailing separators and empty tokens from the path string.
- If you use ',' as a decimal separator in your locale, convert to '.' (and use ' ' or ',' as the coordinate separator per SVG path grammar) before parsing.
Example fix
// before (locale comma as decimal, plus stray comma)
geometry.Parse("M0,0 L10,5,5,0");
// after
geometry.Parse("M0,0 L10,5 5,0"); Defensive patterns
Strategy: validation
Validate before calling
static bool AllNumbersWellFormed(string path)
{
// split on command letters/separators and double.TryParse each token
// with CultureInfo.InvariantCulture; reject empties/non-numbers.
return true;
} Try / catch
try { parser.Parse(data); }
catch (InvalidDataException ex) when (ex.Message == "Invalid double value")
{ /* report which numeric token is malformed */ } Prevention
- Generate numbers with CultureInfo.InvariantCulture ('.' decimal separator).
- Trim trailing separators; never leave an empty token after a comma.
- Validate externally sourced path data before handing it to Parse().
When it happens
Trigger: Any command whose numeric argument is missing, empty, or non-numeric, e.g. 'M x,y' (letters), 'L' followed by end of string, 'H,' (comma with no number), or 'C1,1,1,1,' (trailing separator with no value).
Common situations: Truncated path strings; stray commas/semicolons instead of expected numbers; localized number formatting using ',' as decimal separator bleeding into a comma-separated coordinate list; copy-paste dropping digits.
Related errors
- Invalid fill rule.
- Invalid fill rule
- Invalid bool rule.
- Invalid bool rule
- Unexpected path command '{c}'.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/a842f8b1c709ffc7.
Report an issue: GitHub.