dotnet/maui · error · BuildException
XC0041
XC0041
Error message
Binding: Indexer did not contain closing bracket.
What it means
Thrown while parsing a compiled-binding path when a path segment contains '[' but no matching ']'. The parser uses LastIndexOf(']') and throws BindingIndexerNotClosed when it returns -1.
Source
Thrown at src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs:831
if (string.IsNullOrWhiteSpace(path))
return true;
path = path.Trim(' ', '.'); //trim leading or trailing dots
var parts = path.Split(['.'], StringSplitOptions.RemoveEmptyEntries);
var properties = new List<(PropertyDefinition property, TypeReference propDeclTypeRef, string indexArg)>();
var previousPartTypeRef = tSourceRef;
foreach (var part in parts)
{
var p = part;
string indexArg = null;
var lbIndex = p.IndexOf('[');
if (lbIndex != -1)
{
var rbIndex = p.LastIndexOf(']');
if (rbIndex == -1)
throw new BuildException(BindingIndexerNotClosed, lineInfo, null);
var argLength = rbIndex - lbIndex - 1;
if (argLength == 0)
throw new BuildException(BindingIndexerEmpty, lineInfo, null);
indexArg = p.Substring(lbIndex + 1, argLength).Trim();
if (indexArg.Length == 0)
throw new BuildException(BindingIndexerEmpty, lineInfo, null);
p = p.Substring(0, lbIndex);
p = p.Trim();
}
if (p.Length > 0)
{
var property = previousPartTypeRef.GetProperty(context.Cache, pd => pd.Name == p && pd.GetMethod != null && pd.GetMethod.IsPublic && !pd.GetMethod.IsStatic, out var propDeclTypeRef);
if (property is null)
{View on GitHub (pinned to f377ff1c5e)
Solutions
- Add the missing closing ']' to complete the indexer.
- Re-check the whole path string for balanced brackets.
- If you did not intend an indexer, remove the '['.
Example fix
<!-- before -->
<Label Text="{Binding Items[0}" />
<!-- after -->
<Label Text="{Binding Items[0]}" /> Defensive patterns
Strategy: validation
Validate before calling
// A binding path segment with '[' must have a closing ']'
static bool IndexersClosed(string path)
=> path.Split('.').All(seg => seg.Count(c => c == '[') == 0
|| seg.Contains(']')); Prevention
- Always balance '[' and ']' in binding paths.
- Re-read the path after editing indexer expressions.
- If not indexing, do not leave a stray '['.
When it happens
Trigger: A binding path with an unterminated indexer, e.g. `{Binding Items[0}`.
Common situations: Manual editing of a binding path that drops the closing bracket; malformed copy-paste.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/06eab6e386761e89.
Report an issue: GitHub.