{"record":{"id":"2af77c5c97eaea3a","repo":"unoplatform/uno","slug":"x-bind-indexing-expects-a-single-literal-argument","errorCode":null,"errorMessage":"x:Bind indexing expects a single literal argument","messagePattern":"x:Bind indexing expects a single literal argument","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/Utils/XBindExpressionParser.cs","lineNumber":322,"sourceCode":"\t\t\t\t_builder.Append(')');\n\t\t\t}\n\n\t\t\tpublic override void VisitLiteralExpression(LiteralExpressionSyntax node)\n\t\t\t{\n\t\t\t\t_builder.Append(node.ToString());\n\t\t\t}\n\n\t\t\tpublic override void VisitElementAccessExpression(ElementAccessExpressionSyntax node)\n\t\t\t{\n\t\t\t\tif (Failed)\n\t\t\t\t{\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (node.ArgumentList.Arguments.Count != 1 ||\n\t\t\t\t\tnode.ArgumentList.Arguments[0].Expression is not LiteralExpressionSyntax index)\n\t\t\t\t{\n\t\t\t\t\tthrow new Exception(\"x:Bind indexing expects a single literal argument\");\n\t\t\t\t}\n\n\t\t\t\tVisit(node.Expression);\n\n\t\t\t\tvar lastType = _lastAccessed.Symbol switch\n\t\t\t\t{\n\t\t\t\t\tIPropertySymbol property => property.Type,\n\t\t\t\t\tIFieldSymbol field => field.Type,\n\t\t\t\t\t_ => throw new Exception(\"Only properties and fields can be indexed.\")\n\t\t\t\t};\n\n\t\t\t\tvar expectedIndexerParameterType = index is LiteralExpressionSyntax indexLiteral && indexLiteral.IsKind(SyntaxKind.StringLiteralExpression)\n\t\t\t\t\t? SpecialType.System_String\n\t\t\t\t\t: SpecialType.System_Int32;\n\t\t\t\tvar indexer = lastType.GetMemberIncludingBaseTypes(expectedIndexerParameterType, (m, arg) => m is IPropertySymbol { IsIndexer: true } p && p.Parameters[0].Type.SpecialType == arg);\n\t\t\t\tif (indexer is not null)\n\t\t\t\t{\n\t\t\t\t\t_lastAccessed = (indexer, IsTopLevelContext: false);","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/Utils/XBindExpressionParser.cs#L304-L340","documentation":"Thrown by the Roslyn-based x:Bind expression visitor (VisitElementAccessExpression) when an indexer '[]' in an x:Bind expression does not have exactly one argument, or that argument is not a literal expression. x:Bind only supports indexing by a single string or integer literal.","triggerScenarios":"An x:Bind binding uses an indexer with zero arguments, more than one argument, or a non-literal argument (e.g. a variable, a method call, or a binding path as the index).","commonSituations":"Trying to index a collection with a dynamic/computed value in x:Bind; attempting multi-dimensional indexing; using a variable as the index instead of a hardcoded literal.","solutions":["Ensure the indexer has exactly one argument that is a literal string or integer.","If you need a dynamic index, expose a computed property on your ViewModel/data context and bind to that instead.","Remove any extra arguments from the indexer."],"exampleFix":"<!-- before -->\n<Text Text=\"{x:Bind Items[indexVariable]}\" />\n<Text Text=\"{x:Bind Items[1, 2]}\" />\n<!-- after -->\n<Text Text=\"{x:Bind Items[0]}\" />\n<Text Text=\"{x:Bind CurrentItem}\" />","handlingStrategy":"validation","validationCode":"// Validate x:Bind indexer expressions before build:\n//   - Must have exactly 1 argument\n//   - The argument must be a literal (string or int)\n// Linting regex for simple cases: \\{x:Bind\\s+\\w+\\[(\\d+|\"[^\"]*\")\\]\\}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use literal string or integer indices in x:Bind indexers.","Expose computed properties for dynamic index access.","Never pass variables or method calls as indexer arguments in x:Bind."],"tags":["xbind","xaml","parser","source-generator","indexer"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}