{"record":{"id":"5122481ed37a885c","repo":"dotnet/efcore","slug":"couldn-t-find-method-symbol-for-memberaccesssynt","errorCode":null,"errorMessage":"Couldn't find method symbol for: {memberAccessSyntax}","messagePattern":"Couldn't find method symbol for: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs","lineNumber":474,"sourceCode":"    private void GenerateOperatorInterceptor(\n        IndentedStringBuilder code,\n        Expression operatorExpression,\n        ExpressionSyntax operatorSyntax,\n        SemanticModel semanticModel,\n        int queryNum,\n        int operatorNum,\n        bool isTerminatingOperator,\n        CancellationToken cancellationToken)\n    {\n        // At this point we know we're intercepting a method call invocation.\n        // Extract the MemberAccessExpressionSyntax for the invocation, representing the method being called.\n        var memberAccessSyntax = (operatorSyntax as InvocationExpressionSyntax)?.Expression as MemberAccessExpressionSyntax\n            ?? throw new UnreachableException();\n\n        // Create the parameter list for our interceptor method from the LINQ operator method's parameter list\n        if (semanticModel.GetSymbolInfo(memberAccessSyntax, cancellationToken).Symbol is not IMethodSymbol operatorSymbol)\n        {\n            throw new InvalidOperationException(\"Couldn't find method symbol for: \" + memberAccessSyntax);\n        }\n\n        // Throughout the code generation below, we will only be dealing with the original generic definition of the operator (and\n        // generating a generic interceptor); we'll never be dealing with the concrete types for this invocation, since these may\n        // be unspeakable anonymous types which we can't embed in generated code.\n        operatorSymbol = operatorSymbol.OriginalDefinition;\n\n        // For extension methods, this provides the form which has the \"this\" as its first parameter.\n        // TODO: Validate the below, throw informative (e.g. top-level TVF fails here because non-generic)\n        var reducedOperatorSymbol = operatorSymbol.GetConstructedReducedFrom() ?? operatorSymbol;\n\n        var (sourceVariableName, sourceTypeSymbol) = reducedOperatorSymbol.IsStatic\n            ? (reducedOperatorSymbol.Parameters[0].Name, reducedOperatorSymbol.Parameters[0].Type)\n            : (\"source\", reducedOperatorSymbol.ReceiverType!);\n\n        if (sourceTypeSymbol is not INamedTypeSymbol { TypeArguments: [var sourceElementTypeSymbol] })\n        {\n            throw new UnreachableException($\"Non-IQueryable first parameter in LINQ operator '{operatorSymbol.Name}'\");","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs#L456-L492","documentation":"Thrown in PrecompiledQueryCodeGenerator.GenerateOperatorInterceptor (line 474) when Roslyn's semantic model cannot resolve an IMethodSymbol for the member-access syntax of a LINQ operator being intercepted. The code generator needs the method symbol to build the interceptor's parameter list and signature; if GetSymbolInfo returns null the codegen cannot proceed. It indicates the analyzer could not bind the call to a concrete method definition.","triggerScenarios":"Precompiling a query where the LINQ operator invocation's member-access syntax does not resolve to a method symbol via semanticModel.GetSymbolInfo. This happens when operatorSyntax is an InvocationExpressionSyntax but its Expression is not a MemberAccessExpressionSyntax that binds to a method, or when referenced assemblies/metadata are missing so overload/binding resolution fails.","commonSituations":"The Roslyn Compilation used for precompilation is missing references (e.g. System.Linq, the LINQ provider assembly, or the project's own dependencies). Calling an extension method from an assembly not referenced by the analysis compilation. Source generators/analyzers running against a project whose transitive references are incomplete. Bugs where a non-method member access reaches the interceptor generator.","solutions":["Ensure the project being analyzed has complete assembly references, especially System.Linq.Queryable/Enumerable and the EF provider assembly, so the operator's method symbol can bind.","Reproduce the exact query in the message and simplify it to identify which LINQ operator fails to bind; replace or remove that operator.","Upgrade the EF Core tools/analyzers to a version matching your runtime, since symbol resolution depends on the analyzer's view of referenced assemblies.","Exclude the offending query from precompilation if its operator cannot be resolved in the analysis context."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Ensure the analysis compilation can resolve the operator method symbol before generating\nvar symbol = semanticModel.GetSymbolInfo(memberAccessSyntax, ct).Symbol as IMethodSymbol;\nif (symbol is null) { /* skip or report this query rather than generate */ }","typeGuard":null,"tryCatchPattern":"try { /* generate interceptor */ }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Couldn't find method symbol\"))\n{ /* collect as a per-query precompilation error, skip the query */ }","preventionTips":["Keep the analyzed project's references complete (System.Linq, provider, EF assemblies).","Avoid LINQ operators whose method symbol cannot bind in the analysis context.","Run precompilation on a project that compiles cleanly first."],"tags":["ef-core","precompiled-query","roslyn","code-generation","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}