{"record":{"id":"a2fbe8e62ffbeafe","repo":"dotnet/efcore","slug":"arraycreation-multi-dimensional-array-implicita","errorCode":null,"errorMessage":"ArrayCreation: multi-dimensional array: {implicitArrayCreation}","messagePattern":"ArrayCreation: multi-dimensional array: (.+?)","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":477,"sourceCode":"            $\"Encountered unknown identifier name '{identifierName}', which doesn't correspond to a lambda parameter or captured variable\");\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public override Expression VisitImplicitArrayCreationExpression(ImplicitArrayCreationExpressionSyntax implicitArrayCreation)\n    {\n        if (_semanticModel.GetTypeInfo(implicitArrayCreation).Type is not IArrayTypeSymbol arrayTypeSymbol)\n        {\n            throw new InvalidOperationException($\"ArrayCreation: non-array type symbol: {implicitArrayCreation}\");\n        }\n\n        if (arrayTypeSymbol.Rank > 1)\n        {\n            throw new NotImplementedException($\"ArrayCreation: multi-dimensional array: {implicitArrayCreation}\");\n        }\n\n        var elementType = ResolveType(arrayTypeSymbol.ElementType);\n        Check.DebugAssert(elementType is not null);\n\n        var initializers = implicitArrayCreation.Initializer.Expressions.Select(e => Visit(e));\n\n        return NewArrayInit(elementType, initializers);\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public override Expression VisitInterpolatedStringExpression(InterpolatedStringExpressionSyntax interpolatedString)\n    {","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L459-L495","documentation":"Thrown by VisitImplicitArrayCreationExpression when an implicit array creation expression (e.g. new[] { ... }) has a rank greater than one. The CSharpToLinqTranslator only supports single-dimensional (rank-1) arrays because LINQ expression trees have no factory for multi-dimensional array initialization. This is a NotImplementedException representing an unimplemented feature gap, not a usage error per se.","triggerScenarios":"A precompiled LINQ query contains an implicit multi-dimensional array creation such as `var m = new[,] { { 1, 2 }, { 3, 4 } };` or any implicit `new[]`-style expression whose Roslyn IArrayTypeSymbol.Rank > 1. The translator visits the syntax node, calls GetTypeInfo, sees Rank > 1, and throws immediately.","commonSituations":"Developers who embed matrix/grid data structures inside precompiled query expressions, or who pass lookup tables (e.g. coordinate maps, conversion tables) inline within the query lambda. Rare in typical EF query code; more common in domain logic that happens to be inside a precompiled query scope.","solutions":["Rewrite the query to remove the multi-dimensional array — store the data in a flat single-dimensional array or a List<List<T>> and index into it, or hoist the array out of the query into a field/property that is captured rather than constructed inline.","If the array is a constant lookup, move it outside the precompiled query entirely and reference it as a captured variable so the translator never visits the array creation node.","File an issue / contribute support to the translator if the feature is important for your scenario; it is explicitly unimplemented (NotImplementedException), not forbidden by design."],"exampleFix":"// before\nvar query = ctx.Blogs.Where(b => new[,] { { 1, 2 } }.Length > 0 && b.Id > 0);\n\n// after\nvar matrix = new[,] { { 1, 2 } };\nvar query = ctx.Blogs.Where(b => b.Id > 0); // matrix captured, not constructed inline","handlingStrategy":"validation","validationCode":"// Before precompiling, scan query lambdas for multi-dimensional array creation\n// Use Roslyn to check: any ImplicitArrayCreationExpressionSyntax or ArrayCreationExpressionSyntax\n// whose type info has Rank > 1 inside the query's syntax tree\nvar arrayNodes = querySyntaxTree.DescendantNodes()\n    .OfType<ArrayCreationExpressionSyntax>()\n    .Where(n => semanticModel.GetTypeInfo(n).Type is IArrayTypeSymbol { Rank: > 1 });\nif (arrayNodes.Any())\n    ReportError(\"Multi-dimensional arrays are not supported in precompiled queries\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid multi-dimensional arrays inside precompiled query lambdas — store such data in fields and reference them as captured variables instead.","Run the EF Core precompilation in CI early so unsupported constructs surface before runtime.","Keep precompiled queries simple: arithmetic, property access, and standard LINQ methods only."],"tags":["precompiled-queries","roslyn","expression-tree","array","csharp-syntax","not-implemented"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}