{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L527-L563","documentation":"Thrown by VisitInvocationExpression when Roslyn's GetSymbolInfo on a method invocation returns a null or non-IMethodSymbol. The translator needs the resolved method symbol to find the corresponding reflection MethodInfo and build a MethodCallExpression. Without the symbol, it cannot determine what method is being called, so it throws InvalidOperationException.","triggerScenarios":"A precompiled query contains a method invocation that Roslyn cannot resolve to a symbol. Causes include: the invoked method doesn't exist (compile error elsewhere), the method is a dynamic invocation (dynamic keyword), the method is a delegate invocation (Func/Action called directly rather than via a named method), the compilation is missing assembly references, or the symbol resolution returned an ErrorSymbol.","commonSituations":"Calling a method from an assembly not referenced by the precompilation Compilation; invoking a delegate variable directly (`myFunc(arg)` instead of a named method); using dynamic dispatch; stale Roslyn compilation state after editing source files; missing NuGet package providing the extension method being called.","solutions":["Ensure all assemblies referenced by the project containing the query are available to the precompilation pipeline (check project references and the --assembly parameter passed to CSharpToLinqTranslator.Load).","If invoking a delegate variable, wrap the call in a named method or restructure to call the underlying method directly so Roslyn resolves it as a method symbol.","Check for compilation diagnostics/errors in the project before precompilation — unresolved symbols here often stem from upstream compile errors.","If the invocation targets a type in an external assembly, pass that assembly via the additionalAssembly parameter of Load()."],"exampleFix":"// before — delegate invocation, Roslyn returns no IMethodSymbol\nFunc<int, bool> pred = x => x > 5;\nvar query = ctx.Blogs.Where(b => pred(b.Id));\n\n// after — inline or use a named method\nvar query = ctx.Blogs.Where(b => b.Id > 5);","handlingStrategy":"validation","validationCode":"// Before precompiling, verify every method invocation resolves to a symbol\nvar unresolvedInvocations = querySyntaxTree.DescendantNodes()\n    .OfType<InvocationExpressionSyntax>()\n    .Where(i => semanticModel.GetSymbolInfo(i).Symbol is not IMethodSymbol);\nif (unresolvedInvocations.Any())\n    ReportError(\"One or more method invocations could not be resolved — check references\");","typeGuard":null,"tryCatchPattern":"// If you invoke the translator programmatically:\ntry { var expr = translator.Translate(node, semanticModel); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Could not find symbol for method invocation\"))\n{\n    // Fallback: do not precompile this query, let it compile at runtime\n    LogPrecompileSkipped(node, ex); \n}","preventionTips":["Ensure the project compiles with zero errors before running precompilation.","Pass all referenced assemblies to CSharpToLinqTranslator.Load via additionalAssembly.","Avoid delegate invocations and dynamic dispatch inside precompiled query lambdas.","Keep method calls to strongly-typed, named methods in referenced assemblies."],"tags":["precompiled-queries","roslyn","symbol-resolution","method-invocation","expression-tree"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}