{"record":{"id":"9c90bb753f6e24a9","repo":"unoplatform/uno","slug":"type-is-unsupported-for-indexing","errorCode":null,"errorMessage":"Type is unsupported for indexing.","messagePattern":"Type is unsupported for indexing\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/Utils/XBindExpressionParser.cs","lineNumber":344,"sourceCode":"\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);\n\n\t\t\t\t_builder.Append(']');\n\t\t\t}\n\n\t\t\tpublic override void VisitArgumentList(ArgumentListSyntax 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\tMainExpression.Arguments = new();\n","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/Utils/XBindExpressionParser.cs#L326-L362","documentation":"Thrown by the Roslyn-based x:Bind expression visitor when the type of the indexed property/field does not expose a matching indexer property. The parser looks for an IPropertySymbol with IsIndexer=true whose single parameter is either System.String (for string-literal indices) or System.Int32 (for numeric-literal indices). If none is found on the type or its base types, this exception fires.","triggerScenarios":"Indexing a property/field whose type does not have a string or int indexer — e.g. indexing a struct or a custom collection that does not expose an indexer property.","commonSituations":"Binding to a custom collection type that only has methods (Add/Get) but no 'this[]' indexer; indexing a value type or a non-indexable type; the index type does not match (e.g. using a string index on a type that only has an int indexer, or vice versa).","solutions":["Ensure the target type exposes a public indexer property (this[string] or this[int]).","If the type only has method-based access, add an indexer property or expose a computed property.","Match the index type to the available indexer — use a string literal for string indexers, an integer for int indexers."],"exampleFix":"// before: MyCollection has no indexer\n<Text Text=\"{x:Bind MyCollection[0]}\" />\n// after: add indexer to MyCollection\n// public string this[int index] => _items[index];\n<Text Text=\"{x:Bind MyCollection[0]}\" />","handlingStrategy":"validation","validationCode":"// Verify the indexed type exposes a public indexer matching the index type:\n// For int index: public T this[int index]\n// For string index: public T this[string key]\n// Check via reflection in a test:\n// typeof(MyType).GetProperties().Any(p => p.GetIndexParameters().Length == 1\n//   && p.GetIndexParameters()[0].ParameterType == typeof(int));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure indexed types expose a public 'this[]' indexer.","Match the index literal type to the indexer parameter type.","For custom collections, add an indexer property if absent."],"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"}