dotnet/efcore · error · NotImplementedException

Generic method on generic type not supported

Error message

Generic method on generic type not supported

What it means

Thrown in PrecompiledQueryCodeGenerator.GenerateInterceptorMethodSignature (line 669) when the LINQ operator being intercepted is both a generic method AND declared on a generic containing type. The interceptor-signature generator handles (generic method, non-generic type), (non-generic method, generic type), and (neither), but explicitly throws NotImplementedException for (true, true). It is a known, unimplemented combination in the precompiled-query code generator.

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 dbf9771522)

Solutions

  1. Rewrite the query to avoid the operator that is a generic method on a generic type; replace it with an equivalent using standard IQueryable/Enumerable operators.
  2. Exclude the query containing that operator from precompiled-query generation so it falls back to the normal pipeline.
  3. Track the EF Core issue for supporting this combination and upgrade once implemented.
  4. If the operator is your own, move it off a generic containing type or make it non-generic where precompilation is required.
Defensive patterns

Strategy: validation

Validate before calling

// Detect the unsupported operator shape before generating
var m = operatorSymbol.OriginalDefinition;
if (m.IsGenericMethod && m.ContainingType.IsGenericType) { /* exclude query from precompilation */ }

Type guard

static bool IsSupportedOperatorShape(IMethodSymbol m)
    => !(m.IsGenericMethod && m.ContainingType.IsGenericType);

Try / catch

try { /* generate signature */ }
catch (NotImplementedException ex) when (ex.Message == "Generic method on generic type not supported")
{ /* exclude this query; fall back to normal execution */ }

Prevention

When it happens

Trigger: Precompiling a query whose LINQ operator symbol has IsGenericMethod == true and ContainingType.IsGenericType == true simultaneously. The switch on those two booleans reaches the (true, true) arm and throws. This is a limitation of the signature-emission logic, not a user config problem.

Common situations: Using a LINQ-like operator (often from an EF extension or a generic helper on a generic static class) that is itself generic and lives on a generic type. Hitting the boundary of the precompiled-query feature's supported operator shapes. Rare with stock System.Linq operators but possible with custom or provider extension methods.

Related errors


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