dotnet/maui · error · BuildException
XC0043
XC0043
Error message
Binding: Unsupported indexer index type: "{0}". What it means
Thrown when a compiled-binding indexer is resolved but its parameter type is neither string, Int32, nor an enum. The compiler only knows how to emit index lookups for those key types, so any other key type (Guid, double, custom struct, etc.) is rejected.
Source
Thrown at src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs:904
&& pd.GetMethod != null
&& TypeRefComparer.Default.Equals(pd.GetMethod.Parameters[0].ParameterType.ResolveGenericParameters(previousPartTypeRef), module.ImportReference(context.Cache, ("mscorlib", "System", "Object")))
&& pd.GetMethod.IsPublic, out indexerDeclTypeRef);
// Try to find an indexer with an enum parameter type
indexer ??= previousPartTypeRef.GetProperty(context.Cache,
pd => pd.Name == indexerName
&& pd.GetMethod != null
&& pd.GetMethod.Parameters[0].ParameterType.ResolveGenericParameters(previousPartTypeRef).ResolveCached(context.Cache)?.IsEnum == true
&& pd.GetMethod.IsPublic, out indexerDeclTypeRef);
properties.Add((indexer, indexerDeclTypeRef, indexArg));
if (indexer != null) //the case when we index on an array, not a list
{
var indexType = indexer.GetMethod.Parameters[0].ParameterType.ResolveGenericParameters(indexerDeclTypeRef);
var indexTypeDef = indexType.ResolveCached(context.Cache);
if (!TypeRefComparer.Default.Equals(indexType, module.TypeSystem.String)
&& !TypeRefComparer.Default.Equals(indexType, module.TypeSystem.Int32)
&& indexTypeDef?.IsEnum != true)
throw new BuildException(BindingIndexerTypeUnsupported, lineInfo, null, indexType.FullName);
previousPartTypeRef = indexer.PropertyType.ResolveGenericParameters(indexerDeclTypeRef);
}
else
{
if (previousPartTypeRef.IsArray)
previousPartTypeRef = previousPartTypeRef.GetElementType();
previousPartTypeRef.ResolveCached(context.Cache);
}
}
}
pathProperties = properties;
return true;
}
static IEnumerable<Instruction> DigProperties(IEnumerable<(PropertyDefinition property, TypeReference propDeclTypeRef, string indexArg)> properties, Dictionary<TypeReference, VariableDefinition> locs, Func<Instruction> fallback, IXmlLineInfo lineInfo, ModuleDefinition module, XamlCache cache = null)
{View on GitHub (pinned to f377ff1c5e)
Solutions
- Expose or bind to a string-, int-, or enum-keyed indexer instead.
- Reshape the source so the data is reachable via a property or a supported key.
- Fall back to a non-compiled (reflection) binding by removing x:DataType from that element.
Example fix
<!-- before (Guid-keyed indexer, unsupported) -->
<Label Text="{Binding Items[item.Guid], x:DataType=vm:Vm}" />
<!-- after: use a string key -->
<Label Text="{Binding Items[item.Key], x:DataType=vm:Vm}" /> Defensive patterns
Strategy: validation
Validate before calling
// Compiled bindings support only string/int/enum indexer keys
static bool IsSupportedIndexKey(Type keyType)
=> keyType == typeof(string) || keyType == typeof(int) || keyType.IsEnum; Type guard
static bool IsCompiledBindingIndexable(Type collectionType, out Type keyType)
{
keyType = collectionType.GetDefaultMembers()?.SelectMany(
t => collectionType.GetProperties().Where(p => p.GetIndexParameters().Length == 1))
.Select(p => p.GetIndexParameters()[0].ParameterType).FirstOrDefault();
return keyType != null && IsSupportedIndexKey(keyType);
} Prevention
- Expose string/int/enum-keyed indexers for compiled-binding sources.
- Avoid Guid/double/custom-struct keys when using x:DataType.
- If you must use unsupported keys, omit x:DataType to use reflection binding.
When it happens
Trigger: Binding to an indexer whose key type is unsupported, e.g. `{Binding Map[someGuid]}` where the indexer is keyed by Guid.
Common situations: Using a dictionary keyed by a non-primitive/custom type in a compiled binding; exposing an indexer with an unusual parameter type.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/5a6c3beab3d1e1d3.
Report an issue: GitHub.