AvaloniaUI/Avalonia · error · ExpressionParseException

Expected '{delimiter}'.

Error message

Expected '{delimiter}'.

What it means

ArgumentListParser.ParseArguments throws ExpressionParseException("Expected '{delimiter}'.") at the line-30 branch when the reader reaches the end of input after consuming an argument but before finding the delimiter or the close bracket. The argument list is truncated mid-stream.

Source

Thrown at src/Avalonia.Base/Data/Core/Parsers/ArgumentListParser.cs:30

                var result = new List<string>();

                r.Take();

                while (!r.End)
                {
                    var argument = r.TakeWhile(c => c != delimiter && c != close && !char.IsWhiteSpace(c));
                    if (argument.IsEmpty)
                    {
                        throw new ExpressionParseException(r.Position, "Expected indexer argument.");
                    }

                    result.Add(argument.ToString());

                    r.SkipWhitespace();

                    if (r.End)
                    {
                        throw new ExpressionParseException(r.Position, $"Expected '{delimiter}'.");
                    }
                    else if (r.TakeIf(close))
                    {
                        return result;
                    }
                    else
                    {
                        if (r.Take() != delimiter)
                        {
                            throw new ExpressionParseException(r.Position, $"Expected '{delimiter}'.");
                        }

                        r.SkipWhitespace();
                    }
                }

                throw new ExpressionParseException(r.Position, $"Expected '{close}'.");
            }

View on GitHub (pinned to 11c5427268)

Solutions

  1. Terminate every indexer argument list with the close bracket (e.g. `Items[0]`).
  2. Validate path strings end with `]` for indexers before use.

Example fix

// before
{Binding Items[0}
// after
{Binding Items[0]}
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate indexer paths are terminated with the close bracket.
static bool IndexerIsTerminated(string path)
{
    int open = path.IndexOf('[');
    if (open < 0) return true;
    return path.IndexOf(']', open) >= 0;
}
if (!IndexerIsTerminated(path)) throw new ArgumentException("Unterminated indexer.");

Try / catch

try { var nodes = BindingExpressionGrammar.Parse(path); }
catch (ExpressionParseException ex) when (ex.Message.Contains("Expected"))
{ /* the path is malformed: check brackets/delimiters */ }

Prevention

When it happens

Trigger: An indexer argument list that is not terminated, e.g. `Items[0` (no closing bracket) — after reading `0`, End is true so neither delimiter nor close can be matched.

Common situations: Truncated binding path strings; string concatenation that drops the closing bracket; copy-paste errors in XAML path attributes.

Related errors


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