{"record":{"id":"9f1374288a6d7d89","repo":"dotnet/efcore","slug":"generic-method-on-generic-type-not-supported","errorCode":null,"errorMessage":"Generic method on generic type not supported","messagePattern":"Generic method on generic type not supported","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs","lineNumber":669,"sourceCode":"        code.DecrementIndent().AppendLine(\"}\").AppendLine();\n\n        void GenerateInterceptorMethodSignature()\n        {\n            code\n                .Append(\"public static \")\n                .Append(_g.TypeExpression(reducedOperatorSymbol.ReturnType).ToFullString())\n                .Append(' ')\n                .Append(interceptorName);\n\n            var (typeParameters, constraints) =\n                (reducedOperatorSymbol.IsGenericMethod, reducedOperatorSymbol.ContainingType.IsGenericType) switch\n                {\n                    (true, false) => (reducedOperatorSymbol.TypeParameters,\n                        ((MethodDeclarationSyntax)_g.MethodDeclaration(reducedOperatorSymbol)).ConstraintClauses),\n                    (false, true) => (reducedOperatorSymbol.ContainingType.TypeParameters,\n                        ((TypeDeclarationSyntax)_g.Declaration(reducedOperatorSymbol.ContainingType)).ConstraintClauses),\n                    (false, false) => ([], []),\n                    (true, true) => throw new NotImplementedException(\"Generic method on generic type not supported\")\n                };\n\n            if (typeParameters.Length > 0)\n            {\n                code.Append('<');\n                for (var i = 0; i < typeParameters.Length; i++)\n                {\n                    if (i > 0)\n                    {\n                        code.Append(\", \");\n                    }\n\n                    code.Append(_g.TypeExpression(typeParameters[i]).ToFullString());\n                }\n\n                code.Append('>');\n            }\n","sourceCodeStart":651,"sourceCodeEnd":687,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs#L651-L687","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Exclude the query containing that operator from precompiled-query generation so it falls back to the normal pipeline.","Track the EF Core issue for supporting this combination and upgrade once implemented.","If the operator is your own, move it off a generic containing type or make it non-generic where precompilation is required."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Detect the unsupported operator shape before generating\nvar m = operatorSymbol.OriginalDefinition;\nif (m.IsGenericMethod && m.ContainingType.IsGenericType) { /* exclude query from precompilation */ }","typeGuard":"static bool IsSupportedOperatorShape(IMethodSymbol m)\n    => !(m.IsGenericMethod && m.ContainingType.IsGenericType);","tryCatchPattern":"try { /* generate signature */ }\ncatch (NotImplementedException ex) when (ex.Message == \"Generic method on generic type not supported\")\n{ /* exclude this query; fall back to normal execution */ }","preventionTips":["Avoid generic methods on generic types in queries you precompile.","Precompile queries in isolation to detect unsupported shapes early."],"tags":["ef-core","precompiled-query","generics","code-generation","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}