AvaloniaUI/Avalonia · error · InvalidDataException
Invalid bool rule.
Error message
Invalid bool rule.
What it means
Thrown by the private ReadBool helper when the remaining span is empty at the point a boolean flag is expected. ReadBool reads single '0'/'1' characters for arc command flags (large-arc-flag and sweep-flag in an 'A' command). An empty span means the A command's arguments were truncated before both flags were supplied.
Source
Thrown at src/Avalonia.Base/Media/PathMarkupParser.cs:539
span = span.Slice(1);
}
return span;
}
private static ReadOnlySpan<char> SkipWhitespace(ReadOnlySpan<char> span)
{
int i = 0;
for (; i < span.Length && char.IsWhiteSpace(span[i]); i++) ;
return span.Slice(i);
}
private static bool ReadBool(ref ReadOnlySpan<char> span)
{
span = SkipWhitespace(span);
if (span.IsEmpty)
{
throw new InvalidDataException("Invalid bool rule.");
}
var c = span[0];
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)View on GitHub (pinned to 11c5427268)
Solutions
- Provide all seven arc arguments: rx,ry x-axis-rotation large-arc-flag sweep-flag x,y.
- Use '0' or '1' for both flags (e.g. large-arc-flag=0, sweep-flag=1).
- Validate the arc token count before parsing if generating path data programmatically.
Example fix
// before (missing sweep flag)
geometry.Parse("M0,0 A5,5 0 1 10,0");
// note: only one bool was supplied in a truncated string like "M0,0 A5,5 0 0"
// after
geometry.Parse("M0,0 A5,5 0 0 1 10,0"); Defensive patterns
Strategy: validation
Validate before calling
// For each 'A' command, count arguments; require >= 7 tokens // (rx,ry,rot,large-arc-flag,sweep-flag,x,y). Throw/sanitize if fewer. static bool ArcHasFlags(ReadOnlySpan<char> arcArgs) => /* parse & ensure 2 flag chars present */ true;
Type guard
static bool IsBoolFlagChar(char c) => c is '0' or '1';
Try / catch
try { parser.Parse(data); }
catch (InvalidDataException ex) when (ex.Message == "Invalid bool rule.")
{ /* arc flags missing — report truncated A command */ } Prevention
- Always emit both arc flags when generating path data.
- Run path strings through an SVG-path lint/validator when they originate from external sources.
When it happens
Trigger: An arc 'A' command missing its boolean flags, e.g. 'M0,0 A5,5 0' (missing large-arc-flag and sweep-flag), or 'M0,0 A5,5 0 0' (missing the sweep-flag).
Common situations: Hand-editing arc path data and dropping the trailing flags; converting SVG arcs and losing the flag fields; locale/format tools that strip trailing tokens.
Related errors
- Invalid bool rule
- Invalid fill rule.
- Invalid fill rule
- Invalid double value
- Unexpected path command '{c}'.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/27ec028139fa27c1.
Report an issue: GitHub.