dotnet/maui · error · FormatException

Indexer did not contain arguments

Error message

Indexer did not contain arguments

What it means

Thrown while parsing an indexer segment when the brackets contain no argument (argLength == 0), i.e. an empty indexer like '[]'. The indexer requires at least one character between '[' and ']' to identify the key/ index.

Source

Thrown at src/Controls/src/Core/BindingExpression.cs:248

			string[] pathParts = p.Split(ExpressionSplit);
			for (var i = 0; i < pathParts.Length; i++)
			{
				string part = pathParts[i].Trim();
				if (part == string.Empty)
					throw new FormatException("Path contains an empty part");

				BindingExpressionPart indexer = null;

				int lbIndex = part.IndexOf("[", StringComparison.Ordinal);
				if (lbIndex != -1)
				{
					int rbIndex = part.Length - 1;
					if (part[rbIndex] != ']')
						throw new FormatException("Indexer did not contain closing bracket");

					int argLength = rbIndex - lbIndex - 1;
					if (argLength == 0)
						throw new FormatException("Indexer did not contain arguments");

					string argString = part.Substring(lbIndex + 1, argLength);
					indexer = new BindingExpressionPart(this, argString, true);

					part = part.Substring(0, lbIndex);
					part = part.Trim();
				}
				if (part.Length > 0)
				{
					var next = new BindingExpressionPart(this, part);
					last.NextPart = next;
					_parts.Add(next);
					last = next;
				}
				if (indexer != null)
				{
					last.NextPart = indexer;
					_parts.Add(indexer);

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Ensure the index/key value is non-empty before building the path.
  2. Validate the path with a regex that rejects empty indexer brackets (brackets containing no argument).
  3. Fall back to a safe default index or skip the indexer when the value is missing.

Example fix

// before
var path = $"Items[{index}]"; // index == ""

// after
if (string.IsNullOrEmpty(index))
    throw new ArgumentException("Index must be non-empty", nameof(index));
var path = $"Items[{index}]";
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(index))
    throw new ArgumentException("Indexer key must be non-empty", nameof(index));
var path = $"Items[{index}]";

Type guard

static bool IsValidIndexer(string path) =>
    !Regex.IsMatch(path, @"\[\s*\]"); // reject empty []

Prevention

When it happens

Trigger: Paths like "Items[]", "Dict[]". Building a path with an empty index variable: $"Items[{index}]" where index is empty.

Common situations: Index variable is null or empty string due to uninitialized state. Conditional path building that omits the index value. Deserialization producing empty indexer keys.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/3681a58d40391458. Report an issue: GitHub.