dotnet/efcore · error · NotImplementedException
IndexExpression with multiple arguments
Error message
IndexExpression with multiple arguments
What it means
VisitIndex only renders single-argument indexers (obj[arg]) via ElementAccessExpression with one argument. An IndexExpression with more than one argument — a multidimensional array access like arr[i,j] or a multi-parameter indexer this[int,int] — has no handled rendering, so it throws NotImplementedException.
Source
Thrown at src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs:1911
break;
case MethodBase method:
_methodUnsafeAccessors[method] = unsafeAccessorDeclaration;
break;
default:
throw new UnreachableException();
}
return unsafeAccessorDeclaration;
}
/// <inheritdoc />
protected override Expression VisitIndex(IndexExpression index)
{
using var _ = ChangeContext(ExpressionContext.Expression);
if (index.Arguments.Count > 1)
{
throw new NotImplementedException("IndexExpression with multiple arguments");
}
Result =
ElementAccessExpression(Translate<ExpressionSyntax>(index.Object!))
.WithArgumentList(
BracketedArgumentList(
SingletonSeparatedList(
Argument(
Translate<ExpressionSyntax>(index.Arguments.Single())))));
return index;
}
/// <inheritdoc />
protected override Expression VisitMethodCall(MethodCallExpression call)
{
if (call.Method.DeclaringType is null)
{View on GitHub (pinned to dbf9771522)
Solutions
- Switch from a rectangular array to a jagged array (int[][]) so indexing becomes nested single-argument accesses arr[i][j].
- Replace indexer usage with an explicit method call that the translator can render.
- Avoid multidimensional arrays and multi-parameter indexers in precompiled query expressions.
Example fix
// before int[,] grid; ... grid[i, j] // IndexExpression with 2 args -> throws // after int[][] grid; ... grid[i][j] // nested single-arg index expressions
Defensive patterns
Strategy: validation
Validate before calling
// Flag multi-argument index expressions
protected override Expression VisitIndex(IndexExpression i) { if (i.Arguments.Count > 1) Found = true; return i; } Prevention
- Prefer jagged arrays (T[][]) over rectangular arrays (T[,]).
- Replace multi-parameter indexers with explicit method calls.
- Avoid multidimensional arrays in compiled queries.
When it happens
Trigger: Indexing into a two-or-more-dimensional array, or invoking a multi-parameter indexer, inside a precompiled query or model lambda.
Common situations: Using rectangular (multidimensional) arrays in queries; types exposing this[T1,T2] indexers referenced from compiled expressions.
Related errors
- DebugInfo nodes are not supporting when translating expressi
- Null argument in VisitLabelTarget
- Non-void label target
- Unable to translate type '{type}'.
- Private static field access
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/eee038afe50ef584.
Report an issue: GitHub.