dotnet/efcore · error · InvalidOperationException

ArrayCreation: non-array type symbol: {implicitArrayCreation

Error message

ArrayCreation: non-array type symbol: {implicitArrayCreation}

What it means

Thrown by VisitImplicitArrayCreationExpression when translating an implicit array literal (new[] { ... }) but Roslyn's semantic model reports a type that is not an IArrayTypeSymbol. The translator can only build a NewArrayInit expression for a genuine single-dimensional array type, so a non-array (or null) type symbol is an internal inconsistency it cannot proceed from.

Source

Thrown at src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:472

                            localSymbol.Name,
                            localSymbol.NullableAnnotation is NullableAnnotation.NotAnnotated)));
        }

        throw new InvalidOperationException(
            $"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

View on GitHub (pinned to dbf9771522)

Solutions

  1. Give the array literal an explicit element type: new int[] { ... } instead of new[] { ... }
  2. Hoist the array out of the precompiled query into a local variable captured by the query
  3. If it reproduces with trivial code, report it as an EF Core precompiled-queries bug with a minimal repro

Example fix

// before
var q = ctx.Blogs.Where(b => new[] { b.Id }.Contains(b.Id));
// after (explicit type + hoisted)
var ids = new int[] { 1, 2 };
var q = ctx.Blogs.Where(b => ids.Contains(b.Id));
Defensive patterns

Strategy: validation

Validate before calling

// Before precompiling, ensure all array literals in the query have a resolvable element type.
// Prefer explicit element types over 'new[]'.
var ok = queryExpr.ToString(); // if this contains "new[]", review each occurrence
// Static check: warn on implicit array creation in precompiled query source.

Prevention

When it happens

Trigger: An implicit array creation expression (e.g. new[] { a, b }) appears inside a precompiled query, and _semanticModel.GetTypeInfo(node).Type is null or not an IArrayTypeSymbol. Typically a malformed/inferred array literal whose element type failed to resolve, or an edge case in generic array inference.

Common situations: Rare and usually not reachable with normal user code; indicates either a translator bug or an unusual array literal whose inferred element type is an error/unresolved type (e.g. new[] { unresolvedVar, 1 }).

Related errors


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