dotnet/efcore · error · InvalidOperationException

ObjectCreation: couldn't find IMethodSymbol for constructor:

Error message

ObjectCreation: couldn't find IMethodSymbol for constructor: {objectCreation}

What it means

VisitObjectCreationExpression throws InvalidOperationException when a new X(...) expression cannot be resolved to an IMethodSymbol for its constructor. Without the constructor symbol the translator cannot locate the constructor to build a NewExpression.

Source

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

            ? expression.Type.GetArrayRank() != 1
                ? throw new NotImplementedException("MemberAccess on multi-dimensional array")
                : (Expression)ArrayLength(expression)
            : MakeMemberAccess(
                expression is ConstantExpression { Value: Type } ? null : expression,
                memberInfo);
    }

    /// <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 VisitObjectCreationExpression(ObjectCreationExpressionSyntax objectCreation)
    {
        if (_semanticModel.GetSymbolInfo(objectCreation).Symbol is not IMethodSymbol constructorSymbol)
        {
            throw new InvalidOperationException($"ObjectCreation: couldn't find IMethodSymbol for constructor: {objectCreation}");
        }

        Check.DebugAssert(constructorSymbol.MethodKind == MethodKind.Constructor);

        var type = ResolveType(constructorSymbol.ContainingType);

        // Find the reflection constructor that matches the constructor symbol's signature
        var parameterTypes = constructorSymbol.Parameters.Select(ps => ResolveType(ps.Type)).ToArray();
        var constructor = type.GetConstructor(parameterTypes);

        var newExpression = constructor is not null
            ? New(
                constructor,
                objectCreation.ArgumentList?.Arguments.Select(a => Visit(a)) ?? [])
            : parameterTypes.Length == 0 // For structs, there's no actual parameterless constructor
                ? New(type)
                : throw new InvalidOperationException($"ObjectCreation: Missing constructor: {objectCreation}");

View on GitHub (pinned to dbf9771522)

Solutions

  1. Reference the assembly that defines the type
  2. Ensure the type and its constructor compile without errors
  3. Use the parameterless constructor if available

Example fix

// before (type in unreferenced assembly)
var p = new ExternalDto(b.Id);
// after (use a referenced type / project the values directly)
var p = new { Id = b.Id };
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the constructed type and its constructor are referenced and compile.
var ctor = typeof(ExternalDto).GetConstructors().FirstOrDefault();
if (ctor is null) { /* add assembly reference / fix compile errors */ }

Prevention

When it happens

Trigger: Constructing a type whose constructor is unresolvable: the type lives in an unreferenced assembly, is an error type, or the source has other compile errors preventing binding.

Common situations: new SomeType() where SomeType is in an assembly not referenced by the precompilation; constructing types defined in code with active compile errors; generic types whose constructor can't be resolved.

Related errors


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