{"record":{"id":"67c49697e04a3be2","repo":"dotnet/efcore","slug":"objectcreation-couldn-t-find-imethodsymbol-for-co","errorCode":null,"errorMessage":"ObjectCreation: couldn't find IMethodSymbol for constructor: {objectCreation}","messagePattern":"ObjectCreation: couldn't find IMethodSymbol for constructor: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":821,"sourceCode":"            ? expression.Type.GetArrayRank() != 1\n                ? throw new NotImplementedException(\"MemberAccess on multi-dimensional array\")\n                : (Expression)ArrayLength(expression)\n            : MakeMemberAccess(\n                expression is ConstantExpression { Value: Type } ? null : expression,\n                memberInfo);\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public override Expression VisitObjectCreationExpression(ObjectCreationExpressionSyntax objectCreation)\n    {\n        if (_semanticModel.GetSymbolInfo(objectCreation).Symbol is not IMethodSymbol constructorSymbol)\n        {\n            throw new InvalidOperationException($\"ObjectCreation: couldn't find IMethodSymbol for constructor: {objectCreation}\");\n        }\n\n        Check.DebugAssert(constructorSymbol.MethodKind == MethodKind.Constructor);\n\n        var type = ResolveType(constructorSymbol.ContainingType);\n\n        // Find the reflection constructor that matches the constructor symbol's signature\n        var parameterTypes = constructorSymbol.Parameters.Select(ps => ResolveType(ps.Type)).ToArray();\n        var constructor = type.GetConstructor(parameterTypes);\n\n        var newExpression = constructor is not null\n            ? New(\n                constructor,\n                objectCreation.ArgumentList?.Arguments.Select(a => Visit(a)) ?? [])\n            : parameterTypes.Length == 0 // For structs, there's no actual parameterless constructor\n                ? New(type)\n                : throw new InvalidOperationException($\"ObjectCreation: Missing constructor: {objectCreation}\");\n","sourceCodeStart":803,"sourceCodeEnd":839,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L803-L839","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reference the assembly that defines the type","Ensure the type and its constructor compile without errors","Use the parameterless constructor if available"],"exampleFix":"// before (type in unreferenced assembly)\nvar p = new ExternalDto(b.Id);\n// after (use a referenced type / project the values directly)\nvar p = new { Id = b.Id };","handlingStrategy":"validation","validationCode":"// Ensure the constructed type and its constructor are referenced and compile.\nvar ctor = typeof(ExternalDto).GetConstructors().FirstOrDefault();\nif (ctor is null) { /* add assembly reference / fix compile errors */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reference the assembly that defines any type constructed inside a precompiled query","Resolve all compile errors in the source before precompiling","Prefer parameterless constructors for types constructed in queries"],"tags":["efcore","precompiled-queries","roslyn","object-construction","csharp"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}