AvaloniaUI/Avalonia · error · ExpressionParseException
Expected indexer argument.
Error message
Expected indexer argument.
What it means
ArgumentListParser.ParseArguments throws ExpressionParseException('Expected indexer argument.') when, inside an argument list, TakeWhile consumes nothing because the next character is the delimiter, the close bracket, or whitespace. This means an argument slot is empty (e.g. `[]`, `[,0]`, or `[ ]`).
Source
Thrown at src/Avalonia.Base/Data/Core/Parsers/ArgumentListParser.cs:21
namespace Avalonia.Data.Core.Parsers
{
internal static class ArgumentListParser
{
public static IList<string> ParseArguments(this ref CharacterReader r, char open, char close, char delimiter = ',')
{
if (r.Peek == open)
{
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)
{View on GitHub (pinned to 11c5427268)
Solutions
- Provide a non-empty value for every indexer argument.
- When building paths programmatically, filter out empty tokens before joining with the delimiter.
Example fix
// before
{Binding Items[]}
{Binding Matrix[,1]}
// after
{Binding Items[0]}
{Binding Matrix[0,1]} Defensive patterns
Strategy: validation
Validate before calling
// Reject indexer paths with empty argument slots before binding.
static bool IndexerArgsAreValid(string path)
{
// crude check: no empty slots between [ and ]
int start = path.IndexOf('[');
if (start < 0) return true;
int end = path.IndexOf(']', start);
if (end < 0) return false;
var inner = path.Substring(start + 1, end - start - 1);
foreach (var tok in inner.Split(','))
if (string.IsNullOrWhiteSpace(tok)) return false;
return true;
}
if (!IndexerArgsAreValid(path)) throw new ArgumentException("Empty indexer argument."); Try / catch
try { var nodes = BindingExpressionGrammar.Parse(path); }
catch (ExpressionParseException ex) when (ex.Message.Contains("Expected indexer argument"))
{ /* fix the path: fill empty indexer slots */ } Prevention
- Always supply a value for every indexer slot.
- When building paths dynamically, drop empty tokens.
- Lint binding path strings in CI/XAML validation.
When it happens
Trigger: A binding path indexer with an empty argument, such as `Items[]`, `Items[,1]`, or whitespace-only `Items[ ]`.
Common situations: Typing a binding path with missing index values; dynamically building a path string and leaving an empty slot; trailing/leading delimiter inside brackets.
Related errors
- Expected '{delimiter}'.
- Expected '{close}'.
- Expected '{open}'.
- Expected end of expression.
- Could not convert list index '{i}' of type '{argument}' to '
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/85df59d42fa7e66d.
Report an issue: GitHub.