{"record":{"id":"f91c0d910ffa269d","repo":"dotnet/efcore","slug":"could-not-find-symbol-for-method-invocation-invo","errorCode":null,"errorMessage":"Could not find symbol for method invocation: {invocation}","messagePattern":"Could not find symbol for method invocation: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":545,"sourceCode":"                        nameof(FormattableStringFactory.Create), [typeof(string), typeof(object[])])!,\n\n                _ => _stringFormatMethod ??= typeof(string).GetMethod(nameof(string.Format), [typeof(string), typeof(object[])])!\n            },\n            Constant(formatBuilder.ToString()),\n            NewArrayInit(typeof(object), arguments));\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 VisitInvocationExpression(InvocationExpressionSyntax invocation)\n    {\n        if (_semanticModel.GetSymbolInfo(invocation).Symbol is not IMethodSymbol methodSymbol)\n        {\n            throw new InvalidOperationException(\"Could not find symbol for method invocation: \" + invocation);\n        }\n\n        // First, if the method return type is the user's DbContext type (e.g. DbContext local variable, or field/property), return a\n        // constant over that DbContext type; the invocation can serve as the root for a LINQ query we can precompile.\n        if (methodSymbol.ReturnType.Equals(_userDbContextSymbol, SymbolEqualityComparer.Default))\n        {\n            return Constant(_userDbContext);\n        }\n\n        var declaringType = ResolveType(methodSymbol.ContainingType);\n\n        Expression? instance = null;\n        if (!methodSymbol.IsStatic || methodSymbol.IsExtensionMethod)\n        {\n            // In normal method calls (the ones we support), the invocation node is composed on top of a member access\n            if (invocation.Expression is not MemberAccessExpressionSyntax { Expression: var receiver })\n            {\n                throw new NotSupportedException($\"Invocation over non-member access: {invocation}\");","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L527-L563","documentation":"VisitInvocationExpression throws InvalidOperationException when Roslyn's semantic model cannot bind the invoked method to an IMethodSymbol. The translator needs the symbol to map the call to a reflection MethodInfo and emit a MethodCallExpression; without it, translation is impossible.","triggerScenarios":"A method call inside a precompiled query where GetSymbolInfo(invocation).Symbol is not an IMethodSymbol: calls through dynamic, extension methods whose containing namespace/assembly is not referenced by the precompilation, methods on error types, or overload-resolution failures.","commonSituations":"Missing 'using' for an extension method's namespace; calling a custom helper defined in an assembly not passed to the precompilation; using dynamic-typed variables; invoking a method in source that has other compile errors.","solutions":["Add the missing 'using' directive for the extension method's containing namespace","Ensure the assembly defining the method is referenced by the precompiled-query compilation","Replace dynamic-typed arguments with strongly-typed ones","Inline the helper logic or restrict the query to methods available to the translator"],"exampleFix":"// before (helper in unreferenced assembly)\nvar q = ctx.Blogs.Where(b => MyHelpers.IsActive(b));\n// after (method available to the compilation)\nvar q = ctx.Blogs.Where(b => b.Status == \"active\");","handlingStrategy":"validation","validationCode":"// Ensure the query compiles cleanly and all referenced assemblies are passed to the precompilation.\nvar compilation = CSharpCompilation.Create(...)\n    .AddReferences(MetadataReference.CreateFromFile(typeof(MyHelper).Assembly.Location));\n// Verify no 'dynamic' and that all 'using' directives for extension methods are present.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add the 'using' directive for every extension method namespace used in the query","Pass every referenced assembly to the precompiled-query compilation","Avoid dynamic-typed variables inside precompiled queries","Ensure the source has no unrelated compile errors before precompiling"],"tags":["efcore","precompiled-queries","roslyn","method-resolution","csharp"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}