{"record":{"id":"787f3a469f7f1115","repo":"dotnet/efcore","slug":"invocation-found-definitionmethodinfos-length-m","errorCode":null,"errorMessage":"Invocation: Found {definitionMethodInfos.Length} matches for generic method: {invocation}","messagePattern":"Invocation: Found (.+?) matches for generic method: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":627,"sourceCode":"\n                        for (var i = 0; i < candidateParams.Length; i++)\n                        {\n                            var translatedParamType = ResolveType(originalDefinition.Parameters[i].Type, methodTypeParameterMap);\n                            if (translatedParamType != candidateParams[i].ParameterType)\n                            {\n                                return false;\n                            }\n                        }\n\n                        return true;\n                    }\n\n                    return false;\n                }).ToArray();\n\n            if (definitionMethodInfos.Length != 1)\n            {\n                throw new InvalidOperationException(\n                    $\"Invocation: Found {definitionMethodInfos.Length} matches for generic method: {invocation}\");\n            }\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)","sourceCodeStart":609,"sourceCodeEnd":645,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L609-L645","documentation":"When translating a generic method call, the translator reflects over the declaring type to locate exactly one open generic method definition matching name, type-parameter count, parameter count, and parameter signatures. If it finds zero or more than one candidate it cannot unambiguously call MakeGenericMethod and throws InvalidOperationException.","triggerScenarios":"A generic method invocation where GetMethods() yields != 1 matching generic definition: zero matches (method hidden/inaccessible, signature mismatch from by-ref/custom modifiers) or multiple structurally-identical overloads.","commonSituations":"Custom generic extension methods with several overloads sharing arity and parameter count; generic methods on types with complex generic inheritance; methods whose reflection signature differs from the Roslyn symbol due to ref/in/out modifiers or compiler-generated parameters.","solutions":["Disambiguate by calling a uniquely-named overload or a non-generic method","Ensure the generic method is public so reflection sees a single definition","Simplify the call (remove unnecessary generic arguments or by-ref parameters)","If it reproduces with normal code, report it to EF Core with a minimal repro"],"exampleFix":"// before\nvar q = ctx.Blogs.Where(b => Wrapper<int>.Transform(b.Id));\n// after (non-generic, uniquely-named)\nvar q = ctx.Blogs.Where(b => Wrapper.TransformInt(b.Id));","handlingStrategy":"validation","validationCode":"// Ensure generic methods called in the query have a single resolvable public definition.\nvar mi = typeof(MyType).GetMethods()\n    .Where(m => m.IsGenericMethodDefinition && m.Name == nameof(MyType.M))\n    .ToArray();\nif (mi.Length != 1) { /* disambiguate before precompiling */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give generic helper methods unique names or arities to avoid reflection ambiguity","Keep generic methods public so reflection sees a single definition","Avoid by-ref/in/out parameters on generic methods used in precompiled queries"],"tags":["efcore","precompiled-queries","generics","reflection","method-resolution"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}