dotnet/efcore · error · InvalidOperationException
Invocation: Found {definitionMethodInfos.Length} matches for
Error message
Invocation: Found {definitionMethodInfos.Length} matches for generic method: {invocation} What it means
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.
Source
Thrown at src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:627
for (var i = 0; i < candidateParams.Length; i++)
{
var translatedParamType = ResolveType(originalDefinition.Parameters[i].Type, methodTypeParameterMap);
if (translatedParamType != candidateParams[i].ParameterType)
{
return false;
}
}
return true;
}
return false;
}).ToArray();
if (definitionMethodInfos.Length != 1)
{
throw new InvalidOperationException(
$"Invocation: Found {definitionMethodInfos.Length} matches for generic method: {invocation}");
}
var definitionMethodInfo = definitionMethodInfos[0];
var typeParams = methodSymbol.TypeArguments.Select(a => ResolveType(a)).ToArray();
methodInfo = definitionMethodInfo.MakeGenericMethod(typeParams);
}
else
{
// Non-generic method
var reducedMethodSymbol = methodSymbol.ReducedFrom ?? methodSymbol;
methodInfo = declaringType.GetMethod(
methodSymbol.Name,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static,
reducedMethodSymbol.Parameters.Select(p => ResolveType(p.Type)).ToArray());
if (methodInfo is null)View on GitHub (pinned to dbf9771522)
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
Example fix
// before var q = ctx.Blogs.Where(b => Wrapper<int>.Transform(b.Id)); // after (non-generic, uniquely-named) var q = ctx.Blogs.Where(b => Wrapper.TransformInt(b.Id));
Defensive patterns
Strategy: validation
Validate before calling
// Ensure generic methods called in the query have a single resolvable public definition.
var mi = typeof(MyType).GetMethods()
.Where(m => m.IsGenericMethodDefinition && m.Name == nameof(MyType.M))
.ToArray();
if (mi.Length != 1) { /* disambiguate before precompiling */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invocation: couldn't find method '{methodSymbol.Name}' on ty
- Could not find symbol for method invocation: {invocation}
- MemberAccess: couldn't find member '{memberSymbol.Name}': {m
- ObjectCreation: Missing constructor: {objectCreation}
- ObjectCreation: couldn't find initialized member '{lValueSym
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/787f3a469f7f1115.
Report an issue: GitHub.