dotnet/efcore · error · InvalidOperationException

ArrayCreation: non-array type symbol: {arrayCreation}

Error message

ArrayCreation: non-array type symbol: {arrayCreation}

What it means

`VisitArrayCreationExpression` expects `GetTypeInfo(arrayCreation).Type` to be an `IArrayTypeSymbol`; if it is not, it throws `InvalidOperationException`. The semantic model failing to report an array type for an explicit `new T[...]` expression means the tree is not properly bound.

Source

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

    public override Expression VisitArgument(ArgumentSyntax argument)
        => VisitArgument(argument, expectedType: null);

    private Expression VisitArgument(ArgumentSyntax argument, Type? expectedType)
        => !argument.RefKindKeyword.IsKind(SyntaxKind.None)
            ? throw new InvalidOperationException($"Argument with ref/out: {argument}")
            : Visit(argument.Expression, expectedType);

    /// <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 VisitArrayCreationExpression(ArrayCreationExpressionSyntax arrayCreation)
    {
        if (_semanticModel.GetTypeInfo(arrayCreation).Type is not IArrayTypeSymbol arrayTypeSymbol)
        {
            throw new InvalidOperationException($"ArrayCreation: non-array type symbol: {arrayCreation}");
        }

        if (arrayTypeSymbol.Rank > 1)
        {
            throw new NotImplementedException($"ArrayCreation: multi-dimensional array: {arrayCreation}");
        }

        var elementType = ResolveType(arrayTypeSymbol.ElementType);
        Check.DebugAssert(elementType is not null);

        return arrayCreation.Initializer is null
            ? NewArrayBounds(elementType, Visit(arrayCreation.Type.RankSpecifiers[0].Sizes[0]))
            : NewArrayInit(elementType, arrayCreation.Initializer.Expressions.Select(e => Visit(e)));
    }

    /// <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. Make sure the tree is part of the compilation that produced the `SemanticModel`.
  2. Add the element type's assembly as a reference / `additionalAssembly`.
  3. Prefer `new[] { ... }` (implicit) only if the element type is fully resolvable.

Example fix

// before
translator.Translate(newExprNode, smFromOtherCompilation);
// after
var sm = compilation.AddSyntaxTrees(tree).GetSemanticModel(tree);
translator.Translate(newExprNode, sm);
Defensive patterns

Strategy: validation

Validate before calling

// Verify the array creation binds to an array type before translating.
if (semanticModel.GetTypeInfo(arrayCreationNode).Type is not IArrayTypeSymbol)
    throw new InvalidOperationException(
        "Array creation could not be resolved to an array type. " +
        "Ensure the element type's assembly is referenced and the tree is in the compilation.");

translator.Translate(arrayCreationNode, semanticModel);

Try / catch

try { translator.Translate(node, semanticModel); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("ArrayCreation: non-array type symbol"))
{ /* fix references/tree membership and retry */ }

Prevention

When it happens

Trigger: Translating an array-creation expression (`new int[] { ... }`) whose type symbol is null or non-array — usually because the `SemanticModel`/`Compilation` cannot bind it (missing references or mismatched trees).

Common situations: Passing a syntax node whose tree was not added to the compilation, or a compilation missing the element type's reference.

Related errors


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