{"record":{"id":"eee038afe50ef584","repo":"dotnet/efcore","slug":"indexexpression-with-multiple-arguments","errorCode":null,"errorMessage":"IndexExpression with multiple arguments","messagePattern":"IndexExpression with multiple arguments","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs","lineNumber":1911,"sourceCode":"                break;\n            case MethodBase method:\n                _methodUnsafeAccessors[method] = unsafeAccessorDeclaration;\n                break;\n            default:\n                throw new UnreachableException();\n        }\n\n        return unsafeAccessorDeclaration;\n    }\n\n    /// <inheritdoc />\n    protected override Expression VisitIndex(IndexExpression index)\n    {\n        using var _ = ChangeContext(ExpressionContext.Expression);\n\n        if (index.Arguments.Count > 1)\n        {\n            throw new NotImplementedException(\"IndexExpression with multiple arguments\");\n        }\n\n        Result =\n            ElementAccessExpression(Translate<ExpressionSyntax>(index.Object!))\n                .WithArgumentList(\n                    BracketedArgumentList(\n                        SingletonSeparatedList(\n                            Argument(\n                                Translate<ExpressionSyntax>(index.Arguments.Single())))));\n\n        return index;\n    }\n\n    /// <inheritdoc />\n    protected override Expression VisitMethodCall(MethodCallExpression call)\n    {\n        if (call.Method.DeclaringType is null)\n        {","sourceCodeStart":1893,"sourceCodeEnd":1929,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs#L1893-L1929","documentation":"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.","triggerScenarios":"Indexing into a two-or-more-dimensional array, or invoking a multi-parameter indexer, inside a precompiled query or model lambda.","commonSituations":"Using rectangular (multidimensional) arrays in queries; types exposing this[T1,T2] indexers referenced from compiled expressions.","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."],"exampleFix":"// before\nint[,] grid;  ... grid[i, j]  // IndexExpression with 2 args -> throws\n// after\nint[][] grid;  ... grid[i][j]  // nested single-arg index expressions","handlingStrategy":"validation","validationCode":"// Flag multi-argument index expressions\nprotected override Expression VisitIndex(IndexExpression i) { if (i.Arguments.Count > 1) Found = true; return i; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer jagged arrays (T[][]) over rectangular arrays (T[,]).","Replace multi-parameter indexers with explicit method calls.","Avoid multidimensional arrays in compiled queries."],"tags":["ef-core","linq","expression-tree","indexers","arrays"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}