{"record":{"id":"7aad9fae932ed42d","repo":"unoplatform/uno","slug":"only-properties-and-fields-can-be-indexed","errorCode":null,"errorMessage":"Only properties and fields can be indexed.","messagePattern":"Only properties and fields can be indexed\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/Utils/XBindExpressionParser.cs","lineNumber":331,"sourceCode":"\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);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tthrow new Exception(\"Type is unsupported for indexing.\");\n\t\t\t\t}\n\n\t\t\t\t_builder.Append('[');\n\n\t\t\t\tVisitLiteralExpression(index);","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/Utils/XBindExpressionParser.cs#L313-L349","documentation":"Thrown by the Roslyn-based x:Bind expression visitor when the expression immediately before an indexer '[]' resolves to a symbol that is neither an IPropertySymbol nor an IFieldSymbol. The switch expression has a default case that throws, covering method calls, events, types, and other symbol kinds.","triggerScenarios":"Indexing the result of a method call in x:Bind, e.g. {x:Bind GetItems()[0]}, where GetItems() is a method symbol rather than a property or field.","commonSituations":"Attempting to call a method and immediately index its return value in x:Bind; indexing a type or event member; the parser visited a member that does not have a property/field backing.","solutions":["Bind to a property or field instead of a method — expose a property that holds the collection.","If you need the method result, create a computed property wrapping the method call and bind to that.","Move the indexing logic into a ViewModel property."],"exampleFix":"<!-- before -->\n<Text Text=\"{x:Bind GetItems()[0]}\" />\n<!-- after -->\n<!-- Add a property: -->\n<!-- public string FirstItem => GetItems()[0]; -->\n<Text Text=\"{x:Bind FirstItem}\" />","handlingStrategy":"validation","validationCode":"// Ensure the expression before '[]' in x:Bind is a property or field, not a method.\n// Review the binding: {x:Bind MyProperty[0]} is valid; {x:Bind MyMethod()[0]} is not.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never index a method call result directly in x:Bind.","Wrap method results in a property and bind to the property.","Ensure the indexed member is declared as a property or field."],"tags":["xbind","xaml","parser","source-generator","indexer"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}