dotnet/efcore · error · NotImplementedException
Named argument
Error message
Named argument
What it means
VisitInvocationExpression throws NotImplementedException when a method argument uses named-argument syntax (Foo(bar: 1)). The translator currently only handles positional arguments; named arguments are not mapped onto parameters.
Source
Thrown at src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:717
destArguments[paramIndex] = Constant(
parameter.DefaultValue is null && parameter.ParameterType.IsValueType
? Activator.CreateInstance(parameter.ParameterType)
: parameter.DefaultValue,
parameter.ParameterType);
continue;
}
var argument = invocation.ArgumentList.Arguments[sourceArgIndex++];
// Positional argument
if (argument.NameColon is null)
{
destArguments[paramIndex] = Visit(argument, parameter.ParameterType);
continue;
}
// Named argument
throw new NotImplementedException("Named argument");
}
Check.DebugAssert(destArguments.All(a => a is not null), "arguments.All(a => a is not null)");
return Call(instance, methodInfo, destArguments!);
IEnumerable<KeyValuePair<string, Type>> GetTypeTypeParameters(INamedTypeSymbol typeSymbol)
{
// TODO: We match Roslyn type parameters by name, not sure that's right; also for the method's generic type parameters
if (typeSymbol.ContainingType is { } containingTypeSymbol)
{
foreach (var kvp in GetTypeTypeParameters(containingTypeSymbol))
{
yield return kvp;
}
}
View on GitHub (pinned to dbf9771522)
Solutions
- Reorder arguments so they are all positional
- Remove the name: prefixes from the call
Example fix
// before var v = ctx.Blogs.Where(b => b.HasFlag(flag: 4)); // after var v = ctx.Blogs.Where(b => b.HasFlag(4));
Defensive patterns
Strategy: validation
Validate before calling
// Detect named arguments in precompiled query source.
static bool UsesNamedArg(string src)
=> System.Text.RegularExpressions.Regex.IsMatch(src, @"\b\w+\s*:\s*\w");
if (UsesNamedArg(querySource)) { /* rewrite to positional args */ } Prevention
- Use only positional arguments in precompiled query method calls
- Order arguments to match parameter order to avoid the temptation of named args
When it happens
Trigger: Any method call inside a precompiled query that uses the name: value syntax, e.g. SomeMethod(x: 1, y: 2).
Common situations: Using named arguments for readability with EF helpers (e.g. Include, HasFlag) or custom utility methods inside a query.
Related errors
- ArrayCreation: non-array type symbol: {implicitArrayCreation
- ArrayCreation: multi-dimensional array: {implicitArrayCreati
- Could not find symbol for method invocation: {invocation}
- Invocation over non-member access: {invocation}
- Invocation: couldn't find method '{methodSymbol.Name}' on ty
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/ec63468a4b5652cd.
Report an issue: GitHub.