dotnet/efcore · error · NotImplementedException

Generic method on generic type not supported

Error message

Generic method on generic type not supported

What it means

Thrown while generating an interceptor method signature when the reduced LINQ operator symbol is a generic method AND its containing type is itself generic. The signature generator can handle either generic type parameters or generic method parameters alone, but not both simultaneously, so it throws NotImplementedException for the (true, true) combination.

Solutions

  1. Avoid using LINQ operators that are generic methods on generic types inside precompiled queries.
  2. Replace the operator with a built-in LINQ operator or a non-generic wrapper.
  3. Wait for / request EF support for combined generic type + method parameters in interceptor generation.
Defensive patterns

Strategy: validation

Validate before calling

// Avoid generic methods on generic types in precompiled-query chains
// Inspect the chosen operator symbol: if reducedSymbol.IsGenericMethod && reducedSymbol.ContainingType.IsGenericType, exclude it.

Try / catch

try { generator.Generate(/*...*/); }
catch (NotImplementedException ex) when (ex.Message.Contains("Generic method on generic type"))
{ /* rewrite the query to avoid that operator, or disable precompilation for it */ }

Prevention

When it happens

Trigger: A precompiled query invokes a LINQ operator that is a generic method declared on a generic type, so the interceptor signature would need to declare both the type's and the method's type parameters with their constraints.

Common situations: Calling custom or library LINQ operators defined as generic methods on generic static classes; extension methods on generic containers used inside a precompiled query chain.

Related errors


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

Appendix: source

Thrown at src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs:669

        code.DecrementIndent().AppendLine("}").AppendLine();

        void GenerateInterceptorMethodSignature()
        {
            code
                .Append("public static ")
                .Append(_g.TypeExpression(reducedOperatorSymbol.ReturnType).ToFullString())
                .Append(' ')
                .Append(interceptorName);

            var (typeParameters, constraints) =
                (reducedOperatorSymbol.IsGenericMethod, reducedOperatorSymbol.ContainingType.IsGenericType) switch
                {
                    (true, false) => (reducedOperatorSymbol.TypeParameters,
                        ((MethodDeclarationSyntax)_g.MethodDeclaration(reducedOperatorSymbol)).ConstraintClauses),
                    (false, true) => (reducedOperatorSymbol.ContainingType.TypeParameters,
                        ((TypeDeclarationSyntax)_g.Declaration(reducedOperatorSymbol.ContainingType)).ConstraintClauses),
                    (false, false) => ([], []),
                    (true, true) => throw new NotImplementedException("Generic method on generic type not supported")
                };

            if (typeParameters.Length > 0)
            {
                code.Append('<');
                for (var i = 0; i < typeParameters.Length; i++)
                {
                    if (i > 0)
                    {
                        code.Append(", ");
                    }

                    code.Append(_g.TypeExpression(typeParameters[i]).ToFullString());
                }

                code.Append('>');
            }

View on GitHub (pinned to 3a2006ef56)