dotnet/efcore · error · InvalidOperationException
ObjectCreation: Missing constructor: {objectCreation}
Error message
ObjectCreation: Missing constructor: {objectCreation} What it means
The constructor symbol resolved, but reflection type.GetConstructor(paramTypes) returned null and the type is not the struct parameterless-constructor case. The constructor is known to Roslyn but not found via reflection, so the translator cannot build the NewExpression with arguments.
Source
Thrown at src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:838
{
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}");
switch (objectCreation.Initializer)
{
// No initializers, just return the NewExpression
case null or { Expressions: [] }:
return newExpression;
// Assignment initializer (new Blog { Name = "foo" })
case { Expressions: [AssignmentExpressionSyntax, ..] }:
return MemberInit(
newExpression,
objectCreation.Initializer.Expressions.Select(e =>
{
if (e is not AssignmentExpressionSyntax { Left: var lValue, Right: var value })
{
throw new NotSupportedException(
$"ObjectCreation: non-assignment initializer expression of type '{e.GetType().Name}': {objectCreation}");
}View on GitHub (pinned to dbf9771522)
Solutions
- Make the constructor public
- Add [InternalsVisibleTo] for the consuming assembly
- Use the parameterless constructor plus property initializers instead
- Avoid by-ref constructor parameters in precompiled queries
Example fix
// before
internal Entity(int id) { Id = id; }
// after
public Entity() { }
// usage: new Entity { Id = b.Id } Defensive patterns
Strategy: validation
Validate before calling
// Confirm the constructor is reflection-discoverable with the exact parameter types.
var ctor = typeof(Entity).GetConstructor(new[] { typeof(int) });
if (ctor is null) { /* make public / add InternalsVisibleTo / drop by-ref params */ } Prevention
- Make constructors used in precompiled queries public, or grant InternalsVisibleTo
- Avoid ref/out/in constructor parameters
- Use parameterless construction plus property initializers where possible
When it happens
Trigger: A non-public constructor, a constructor with by-ref/out/in parameters or custom modifiers whose reflection signature doesn't match, or a constructor defined in a different assembly version than the runtime load.
Common situations: Internal constructors across assemblies; constructors with in/ref parameters; records or types with non-public constructors; interop types.
Related errors
- Invocation: couldn't find method '{methodSymbol.Name}' on ty
- MemberAccess: couldn't find member '{memberSymbol.Name}': {m
- ObjectCreation: couldn't find IMethodSymbol for constructor:
- ObjectCreation: couldn't find initialized member '{lValueSym
- ArrayCreation: non-array type symbol: {implicitArrayCreation
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/599127f882da6630.
Report an issue: GitHub.