{"record":{"id":"5baabd0e59a46ad5","repo":"AvaloniaUI/Avalonia","slug":"indexer-may-not-be-empty","errorCode":null,"errorMessage":"Indexer may not be empty.","messagePattern":"Indexer may not be empty\\.","errorType":"validation","errorClass":"ExpressionParseException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Data/Core/Parsers/BindingExpressionGrammar.cs","lineNumber":262,"sourceCode":"            }\n\n            nodes.Add(new AttachedPropertyNameNode\n            {\n                AcceptsNull = acceptsNull,\n                Namespace = ns,\n                TypeName = owner,\n                PropertyName = name.ToString()\n            });\n            return State.AfterMember;\n        }\n\n        private static State ParseIndexer(ref CharacterReader r, List<INode> nodes)\n        {\n            var args = r.ParseArguments('[', ']');\n\n            if (args.Count == 0)\n            {\n                throw new ExpressionParseException(r.Position, \"Indexer may not be empty.\");\n            }\n\n            nodes.Add(new IndexerNode { Arguments = args });\n            return State.AfterMember;\n        }\n\n        private static State ParseTypeCast(ref CharacterReader r, List<INode> nodes)\n        {\n            bool parseMemberBeforeAddCast = ParseOpenBrace(ref r);\n\n            var (ns, typeName) = ParseTypeName(ref r);\n\n            var result = State.AfterMember;\n\n            if (parseMemberBeforeAddCast)\n            {\n                if (!ParseCloseBrace(ref r))\n                {","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Data/Core/Parsers/BindingExpressionGrammar.cs#L244-L280","documentation":"Thrown by ParseIndexer when ParseArguments('[', ']') returns an empty list — meaning the binding path contains '[]' with no arguments between the brackets. Avalonia's binding mini-language requires at least one indexer argument (e.g. '[0]' or '[key]'); an empty indexer has no meaning and cannot resolve to a property accessor.","triggerScenarios":"Writing 'Foo[]' in a binding path string. ParseArguments returns an empty list only when the open bracket is immediately followed by the close bracket with no argument characters in between (ParseArguments would actually throw 'Expected indexer argument' before returning empty for whitespace-only content, but for the literal '[]' case the while loop body never executes and args.Count stays 0 — actually ParseArguments takes the '[', enters the while loop only if !r.End, and on seeing ']' immediately, r.TakeWhile returns empty and ParseArguments throws 'Expected indexer argument'. So this specific error fires when ParseArguments somehow returns count 0, which occurs when the open bracket is not found at all and ParseArguments returns early).","commonSituations":"Dynamic index generation that produces an empty string inside the brackets; typo where the indexer value was deleted; misunderstanding the binding mini-language thinking '[]' is valid syntax for a default index.","solutions":["Provide at least one argument inside the indexer brackets, e.g. '[0]' or '[key]'.","If building indexer paths dynamically, ensure the index expression is non-empty before constructing the bracket segment.","Replace '[]' with a concrete index value or remove the indexer entirely if no indexing is needed."],"exampleFix":"<!-- before: empty indexer -->\n<TextBox Text=\"{Binding Items[]}\" />\n\n<!-- after: concrete index -->\n<TextBox Text=\"{Binding Items[0]}\" />","handlingStrategy":"validation","validationCode":"// Validate that indexer brackets are not empty\nstatic void ValidateIndexerNotEmpty(string path)\n{\n    for (int i = 0; i < path.Length - 1; i++)\n{\n        if (path[i] == '[' && path[i + 1] == ']')\n            throw new ArgumentException($\"Empty indexer '[]' at position {i} in binding path\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var binding = new Binding(path);\n}\ncatch (ExpressionParseException ex) when (ex.Message.Contains(\"Indexer may not be empty\"))\n{\n    logger.LogError($\"Empty indexer at column {ex.Column}: provide at least one index argument\");\n}","preventionTips":["When building indexer paths dynamically, ensure the index variable is non-empty before wrapping in '[]'.","Use string interpolation only after validating the index: $\"Items[{ValidateIndex(index)}]\".","Prefer numeric constants for indexer arguments in XAML."],"tags":["avalonia","binding","xaml","binding-expression","indexer","parser","syntax-error"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}