{"record":{"id":"df1bcba40706ef1b","repo":"dotnet/efcore","slug":"invocation-couldn-t-find-method-methodsymbol-na","errorCode":null,"errorMessage":"Invocation: couldn't find method '{methodSymbol.Name}' on type '{declaringType.Name}': {invocation}","messagePattern":"Invocation: couldn't find method '(.+?)' on type '(.+?)': (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":647,"sourceCode":"            }\n\n            var definitionMethodInfo = definitionMethodInfos[0];\n            var typeParams = methodSymbol.TypeArguments.Select(a => ResolveType(a)).ToArray();\n            methodInfo = definitionMethodInfo.MakeGenericMethod(typeParams);\n        }\n        else\n        {\n            // Non-generic method\n            var reducedMethodSymbol = methodSymbol.ReducedFrom ?? methodSymbol;\n\n            methodInfo = declaringType.GetMethod(\n                methodSymbol.Name,\n                BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static,\n                reducedMethodSymbol.Parameters.Select(p => ResolveType(p.Type)).ToArray());\n\n            if (methodInfo is null)\n            {\n                throw new InvalidOperationException(\n                    $\"Invocation: couldn't find method '{methodSymbol.Name}' on type '{declaringType.Name}': {invocation}\");\n            }\n        }\n\n        // We have the reflection MethodInfo for the method, prepare the arguments.\n\n        // We can have less arguments than parameters when the method has optional parameters; fill in the missing ones with the default\n        // value.\n        // If the method also has a \"params\" parameter, we also need to take care of that - the syntactic arguments will need to be packed\n        // into the \"params\" array etc.\n        var parameters = methodInfo.GetParameters();\n        var sourceArguments = invocation.ArgumentList.Arguments;\n        var destArguments = new Expression?[parameters.Length];\n        var paramIndex = 0;\n\n        // At the syntactic level, an extension method invocation looks like a normal instance's.\n        // Prepend the instance to the argument list.\n        // TODO: Test invoking extension without extension syntax (as static)","sourceCodeStart":629,"sourceCodeEnd":665,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L629-L665","documentation":"Thrown when a non-generic method cannot be found on the declaring type via reflection GetMethod(name, bindings, paramTypes). The Roslyn symbol gave the method name and parameter types, but Type.GetMethod returned null. This means Roslyn sees the method but the loaded CLR type does not expose it under the same name and signature.","triggerScenarios":"A precompiled query calls a non-generic instance or static method where: the method is private/internal and BindingFlags resolution differs; the method's parameter types resolved through ResolveType differ from the actual reflection parameter types; the declaring type loaded at runtime is a different version than what Roslyn compiled against; the method is an explicit interface implementation (maps to a different name in metadata); or the method is compiler-generated.","commonSituations":"Calling internal methods from a different assembly without InternalsVisibleTo; version skew between the NuGet package referenced at compile time and the one loaded at runtime; calling methods on types from assemblies not passed via additionalAssembly; explicit interface implementation methods whose metadata name includes the interface prefix; methods with optional/ref parameters that change the reflection signature lookup.","solutions":["Verify the method is public or that InternalsVisibleTo is set for the precompilation assembly.","Check for assembly version mismatches — ensure all referenced packages are at consistent versions between compile and precompile phases.","If the method is an explicit interface implementation, call it through the interface type instead of the implementing type.","Pass the external assembly containing the declaring type via the additionalAssembly parameter of CSharpToLinqTranslator.Load().","If the method has ref/out/in parameters, the translator's parameter-type resolution may not match the reflection signature — restructure to avoid passing by reference."],"exampleFix":"// before — calling internal method from different assembly\nvar query = ctx.Items.Where(x => x.CalculateInternalScore() > 10);\n\n// after — make method public, or move logic into the query\nvar query = ctx.Items.Where(x => x.Score > 10);","handlingStrategy":"validation","validationCode":"// Before precompiling, verify non-generic methods are findable via reflection\nforeach (var invocation in querySyntaxTree.DescendantNodes().OfType<InvocationExpressionSyntax>())\n{\n    if (semanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol { IsGenericMethod: false } method)\n    {\n        var declaringType = ResolveTypeForCheck(method.ContainingType);\n        var paramTypes = method.Parameters.Select(p => ResolveTypeForCheck(p.Type)).ToArray();\n        var found = declaringType.GetMethod(method.Name,\n            BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static,\n            null, CallingConventions.Any, paramTypes, null);\n        if (found is null)\n            ReportError($\"Method '{method.Name}' not found via reflection on {declaringType.Name}\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make methods called in precompiled queries public, or add InternalsVisibleTo for the precompilation assembly.","Avoid ref/out/in parameters in methods called from precompiled queries.","Keep all package versions consistent between compile and precompile phases.","Pass external assemblies via additionalAssembly to Load().","Avoid explicit interface implementation method calls."],"tags":["precompiled-queries","roslyn","reflection","method-resolution","expression-tree","assembly-version"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}