AvaloniaUI/Avalonia · error · InvalidDataException

Invalid bool rule

Error message

Invalid bool rule

What it means

Thrown by ReadBool's switch when the flag character read is neither '0' nor '1'. Arc boolean flags must be a single ASCII digit; any other character (a letter, '2'-'9', 'true'/'false', a sign) lands here.

Source

Thrown at src/Avalonia.Base/Media/PathMarkupParser.cs:553

            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)
        {
            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);

View on GitHub (pinned to 11c5427268)

Solutions

  1. Use only '0' or '1' for both the large-arc-flag and the sweep-flag.
  2. Replace 'true'/'false' with '1'/'0' respectively.
  3. Re-validate the arc segment token against the SVG arc grammar (7 numeric-or-flag args).

Example fix

// before
geometry.Parse("M0,0 A5,5 0 true false 10,0");

// after
geometry.Parse("M0,0 A5,5 0 1 0 10,0");
Defensive patterns

Strategy: validation

Validate before calling

if (flagChar is not ('0' or '1')) flagChar = (value ? '1' : '0');

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")
{ /* non-binary arc flag — sanitize to 0/1 */ }

Prevention

When it happens

Trigger: Arc commands with non-binary flags, e.g. 'A5,5 0 true 1 10,0' or 'A5,5 0 2 1 10,0'.

Common situations: Using boolean words ('true'/'false') instead of 0/1; copying flags from a format that uses different tokens; OCR/copy-paste introducing a wrong glyph.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/109ebad0980a984b. Report an issue: GitHub.