unoplatform/uno · error · Exception
Type is unsupported for indexing.
Error message
Type is unsupported for indexing.
What it means
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.
Source
Thrown at src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/Utils/XBindExpressionParser.cs:344
var lastType = _lastAccessed.Symbol switch
{
IPropertySymbol property => property.Type,
IFieldSymbol field => field.Type,
_ => throw new Exception("Only properties and fields can be indexed.")
};
var expectedIndexerParameterType = index is LiteralExpressionSyntax indexLiteral && indexLiteral.IsKind(SyntaxKind.StringLiteralExpression)
? SpecialType.System_String
: SpecialType.System_Int32;
var indexer = lastType.GetMemberIncludingBaseTypes(expectedIndexerParameterType, (m, arg) => m is IPropertySymbol { IsIndexer: true } p && p.Parameters[0].Type.SpecialType == arg);
if (indexer is not null)
{
_lastAccessed = (indexer, IsTopLevelContext: false);
}
else
{
throw new Exception("Type is unsupported for indexing.");
}
_builder.Append('[');
VisitLiteralExpression(index);
_builder.Append(']');
}
public override void VisitArgumentList(ArgumentListSyntax node)
{
if (Failed)
{
return;
}
MainExpression.Arguments = new();
View on GitHub (pinned to 0418340488)
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.
Example fix
// before: MyCollection has no indexer
<Text Text="{x:Bind MyCollection[0]}" />
// after: add indexer to MyCollection
// public string this[int index] => _items[index];
<Text Text="{x:Bind MyCollection[0]}" /> Defensive patterns
Strategy: validation
Validate before calling
// Verify the indexed type exposes a public indexer matching the index type: // For int index: public T this[int index] // For string index: public T this[string key] // Check via reflection in a test: // typeof(MyType).GetProperties().Any(p => p.GetIndexParameters().Length == 1 // && p.GetIndexParameters()[0].ParameterType == typeof(int));
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- x:Bind indexing expects a single literal argument
- Only properties and fields can be indexed.
- Missing parenthesis?
- Expected attached property path to be member access.
- Expected ')' in attached property syntax.
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/9c90bb753f6e24a9.
Report an issue: GitHub.