dotnet/efcore · error · NotImplementedException

Named argument

Error message

Named argument

What it means

Thrown as NotImplementedException when a method invocation argument uses named argument syntax (e.g. Foo(name: value)). The translator's argument-binding loop handles positional arguments, optional parameters, and params arrays, but explicitly throws when it encounters an argument with NameColon set. Named argument binding is an unimplemented feature in the translator.

Solutions

  1. Rewrite the method call to use positional arguments only: remove all `paramName:` prefixes and order arguments to match the method signature.
  2. If the method has many optional parameters, provide all preceding arguments positionally up to the one you need, passing defaults or explicit values for the ones in between.
  3. Disable IDE auto-formatting rules that insert named arguments (e.g. 'Use named arguments' code style) for files containing precompiled queries.
  4. If a third-party source generator produces named arguments, configure it to emit positional arguments for precompiled query code.

Example fix

// before
var query = ctx.Blogs.Where(b => Validate(id: b.Id, mode: CheckMode.Strict));

// after
var query = ctx.Blogs.Where(b => Validate(b.Id, CheckMode.Strict));
Defensive patterns

Strategy: validation

Validate before calling

// Before precompiling, scan for named arguments in method invocations
var namedArgs = querySyntaxTree.DescendantNodes()
    .OfType<InvocationExpressionSyntax>()
    .SelectMany(i => i.ArgumentList?.Arguments ?? new SeparatedSyntaxList<ArgumentSyntax>())
    .Where(a => a.NameColon is not null);
if (namedArgs.Any())
    ReportError("Named arguments are not supported in precompiled queries — use positional arguments");

Prevention

When it happens

Trigger: A precompiled query contains a method call with named arguments: `ctx.Blogs.Where(b => SomeHelper(predicate: b.Id > 5, threshold: 10))`, or any LINQ/operator call where the developer used `paramName:` syntax. The translator encounters `argument.NameColon != null` and throws.

Common situations: Developers who use named arguments for readability in complex LINQ calls; code generated by tools/analyzers that favor named arguments; queries that call methods with many optional parameters where named arguments clarify intent; ReSharper/IDE refactoring that converts positional args to named args.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/ec63468a4b5652cd. Report an issue: GitHub.

Appendix: 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 3a2006ef56)