dotnet/efcore · error · NotImplementedException
ArrayCreation: multi-dimensional array
Error message
ArrayCreation: multi-dimensional array: {implicitArrayCreation} What it means
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.
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.
Example fix
// before
var query = ctx.Blogs.Where(b => new[,] { { 1, 2 } }.Length > 0 && b.Id > 0);
// after
var matrix = new[,] { { 1, 2 } };
var query = ctx.Blogs.Where(b => b.Id > 0); // matrix captured, not constructed inline Defensive patterns
Strategy: validation
Validate before calling
// Before precompiling, scan query lambdas for multi-dimensional array creation
// Use Roslyn to check: any ImplicitArrayCreationExpressionSyntax or ArrayCreationExpressionSyntax
// whose type info has Rank > 1 inside the query's syntax tree
var arrayNodes = querySyntaxTree.DescendantNodes()
.OfType<ArrayCreationExpressionSyntax>()
.Where(n => semanticModel.GetTypeInfo(n).Type is IArrayTypeSymbol { Rank: > 1 });
if (arrayNodes.Any())
ReportError("Multi-dimensional arrays are not supported in precompiled queries"); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- MemberAccess on multi-dimensional array
- Named argument
- ObjectCreation: non-assignment initializer expression of…
- Unsupported syntax node of type
- Could not find symbol for method invocation
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/a2fbe8e62ffbeafe.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:477
$"Encountered unknown identifier name '{identifierName}', which doesn't correspond to a lambda parameter or captured variable");
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Expression VisitImplicitArrayCreationExpression(ImplicitArrayCreationExpressionSyntax implicitArrayCreation)
{
if (_semanticModel.GetTypeInfo(implicitArrayCreation).Type is not IArrayTypeSymbol arrayTypeSymbol)
{
throw new InvalidOperationException($"ArrayCreation: non-array type symbol: {implicitArrayCreation}");
}
if (arrayTypeSymbol.Rank > 1)
{
throw new NotImplementedException($"ArrayCreation: multi-dimensional array: {implicitArrayCreation}");
}
var elementType = ResolveType(arrayTypeSymbol.ElementType);
Check.DebugAssert(elementType is not null);
var initializers = implicitArrayCreation.Initializer.Expressions.Select(e => Visit(e));
return NewArrayInit(elementType, initializers);
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Expression VisitInterpolatedStringExpression(InterpolatedStringExpressionSyntax interpolatedString)
{View on GitHub (pinned to 3a2006ef56)