dotnet/efcore · error · NotImplementedException

ArrayCreation: multi-dimensional array: {implicitArrayCreati

Error message

ArrayCreation: multi-dimensional array: {implicitArrayCreation}

What it means

VisitImplicitArrayCreationExpression throws NotImplementedException when the resolved array type has Rank > 1. Precompiled query translation only supports single-dimensional arrays; multi-dimensional arrays (int[,], string[,,]) cannot be represented via the supported NewArrayInit path.

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 dbf9771522)

Solutions

  1. Replace the multi-dimensional array with a jagged array (T[][]) which is supported
  2. Move the array construction out of the query into a captured local computed beforehand
  3. Flatten the data into a single-dimensional array and compute indices manually

Example fix

// before
var m = new[,] { { 1, 2 }, { 3, 4 } };
// after
var m = new int[][] { new[] { 1, 2 }, new[] { 3, 4 } };
Defensive patterns

Strategy: validation

Validate before calling

// Reject multi-dimensional arrays in precompiled query source.
static bool UsesMultidimArray(string querySource)
    => System.Text.RegularExpressions.Regex.IsMatch(querySource, @"new\s*\[\s*,");
if (UsesMultidimArray(querySource)) { /* rewrite to jagged or hoist */ }

Prevention

When it happens

Trigger: A multi-dimensional array literal such as new[,] { { 1, 2 }, { 3, 4 } } or new int[2, 2] appears inside a precompiled query expression.

Common situations: Matrix/grid/image data structures, board-game state, or math code using T[,] being constructed inside a query that gets precompiled.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/a2fbe8e62ffbeafe. Report an issue: GitHub.