{"record":{"id":"6c55127e5b2a9d01","repo":"dotnet/efcore","slug":"invocation-over-non-member-access-invocation","errorCode":null,"errorMessage":"Invocation over non-member access: {invocation}","messagePattern":"Invocation over non-member access: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":563,"sourceCode":"            throw new InvalidOperationException(\"Could not find symbol for method invocation: \" + invocation);\n        }\n\n        // First, if the method return type is the user's DbContext type (e.g. DbContext local variable, or field/property), return a\n        // constant over that DbContext type; the invocation can serve as the root for a LINQ query we can precompile.\n        if (methodSymbol.ReturnType.Equals(_userDbContextSymbol, SymbolEqualityComparer.Default))\n        {\n            return Constant(_userDbContext);\n        }\n\n        var declaringType = ResolveType(methodSymbol.ContainingType);\n\n        Expression? instance = null;\n        if (!methodSymbol.IsStatic || methodSymbol.IsExtensionMethod)\n        {\n            // In normal method calls (the ones we support), the invocation node is composed on top of a member access\n            if (invocation.Expression is not MemberAccessExpressionSyntax { Expression: var receiver })\n            {\n                throw new NotSupportedException($\"Invocation over non-member access: {invocation}\");\n            }\n\n            instance = Visit(receiver);\n        }\n\n        MethodInfo? methodInfo;\n\n        if (methodSymbol.IsGenericMethod)\n        {\n            var originalDefinition = methodSymbol.OriginalDefinition;\n            if (originalDefinition.ReducedFrom is not null)\n            {\n                originalDefinition = originalDefinition.ReducedFrom;\n            }\n\n            // To accurately find the right open generic method definition based on the Roslyn symbol, we need to create a mapping between\n            // generic type parameter names (based on the Roslyn side) and .NET reflection Types representing those type parameters.\n            // This includes both type parameters immediately on the generic method, as well as type parameters from the method's","sourceCodeStart":545,"sourceCodeEnd":581,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L545-L581","documentation":"For instance or extension method calls the translator expects the invocation node to sit on top of a member access (receiver.Method(...)). A NotSupportedException is thrown when invocation.Expression is not a MemberAccessExpressionSyntax, e.g. a delegate invoked directly as del().","triggerScenarios":"Directly invoking a delegate or Func/Action variable (myDelegate(arg)), invoking the result of a parenthesized expression, or any invocation whose receiver is not a member-access expression.","commonSituations":"Storing a Func<T,bool> in a local and invoking it inside a precompiled query; calling through a delegate field/property; invoking a method group converted to a delegate.","solutions":["Call the target method directly rather than via a delegate variable","Replace the delegate with a direct static or instance method call the translator can bind","Hoist the delegate invocation out of the query into a precomputed captured value"],"exampleFix":"// before\nFunc<int, bool> ok = id => id > 0;\nvar q = ctx.Blogs.Where(b => ok(b.Id));\n// after\nvar q = ctx.Blogs.Where(b => b.Id > 0);","handlingStrategy":"validation","validationCode":"// Flag direct delegate invocations in precompiled query source.\nstatic bool InvokesDelegate(string src)\n    => System.Text.RegularExpressions.Regex.IsMatch(src, @\"\\b\\w+\\s*\\(\") && /* contains a Func/Action local */ false;\n// Prefer: ensure no 'del(...)' style calls; only method calls on member access.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never invoke delegate/Func/Action variables inside a precompiled query","Call methods directly on their receiver (ctx.Blogs.Where(b => Service.IsValid(b)))","Hoist delegate results out of the query into precomputed captured values"],"tags":["efcore","precompiled-queries","delegates","csharp"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}