{"record":{"id":"4c9da8edada50a32","repo":"elsa-workflows/elsa-core","slug":"no-invoke-methods-were-found-use-either-invoke-or-4c9da8","errorCode":null,"errorMessage":"No Invoke methods were found. Use either Invoke or InvokeAsync","messagePattern":"No Invoke methods were found\\. Use either Invoke or InvokeAsync","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Workflows.Core/Pipelines/MiddlewareHelpers.cs","lineNumber":19,"sourceCode":"using System.Reflection;\n\nnamespace Elsa.Workflows.Pipelines;\n\npublic static class MiddlewareHelpers\n{\n    public static MethodInfo GetInvokeMethod(Type middleware)\n    {\n        const string invokeMethodName = \"Invoke\";\n        const string invokeAsyncMethodName = \"InvokeAsync\";\n        var methods = middleware.GetMethods(BindingFlags.Instance | BindingFlags.Public);\n        var invokeMethods = methods.Where(m => string.Equals(m.Name, invokeMethodName, StringComparison.Ordinal) || string.Equals(m.Name, invokeAsyncMethodName, StringComparison.Ordinal)).ToArray();\n\n        switch (invokeMethods.Length)\n        {\n            case > 1:\n                throw new InvalidOperationException(\"Multiple Invoke methods were found. Use either Invoke or InvokeAsync.\");\n            case 0:\n                throw new InvalidOperationException(\"No Invoke methods were found. Use either Invoke or InvokeAsync\");\n        }\n\n        var methodInfo = invokeMethods[0];\n\n        if (!typeof(Task).IsAssignableFrom(methodInfo.ReturnType) && !typeof(ValueTask).IsAssignableFrom(methodInfo.ReturnType))\n            throw new InvalidOperationException($\"The {methodInfo.Name} method must return Task or ValueTask\");\n\n        return methodInfo;\n    }\n}","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Workflows.Core/Pipelines/MiddlewareHelpers.cs#L1-L29","documentation":"GetInvokeMethod throws InvalidOperationException when a middleware type exposes no public instance method named Invoke or InvokeAsync. Elsa pipelines rely on the ASP.NET Core middleware convention for invocation, so a type without such a method cannot be used as middleware. Note the message lacks a trailing period (copied from ASP.NET Core's original text).","triggerScenarios":"Registering a plain class (no Invoke/InvokeAsync instance method) as middleware; defining Invoke as static, internal, or with a typo like invokeAsync; using a middleware defined only as a Func delegate type in the wrong registration overload.","commonSituations":"Renaming Invoke to Handle during refactoring; middleware written as an abstract base expecting a differently-named override; copy-pasting a delegate-based middleware registration for a class-based middleware.","solutions":["Add a public instance method named Invoke or InvokeAsync returning Task or ValueTask","Make sure the method is public and non-static","Verify the class is actually middleware-shaped rather than a handler/delegate","If it's a terminal handler, use the appropriate registration API instead of middleware registration"],"exampleFix":"// before\npublic class MyMiddleware { public Task HandleAsync(Context ctx) => Next(ctx); }\n// after\npublic class MyMiddleware { public Task InvokeAsync(Context ctx) => Next(ctx); }","handlingStrategy":"validation","validationCode":"var ok = typeof(TMiddleware).GetMethods(BindingFlags.Instance | BindingFlags.Public).Any(m => m.Name is \"Invoke\" or \"InvokeAsync\"); if (!ok) throw new InvalidOperationException(\"Middleware lacks Invoke/InvokeAsync.\");","typeGuard":null,"tryCatchPattern":"try { pipelines.UseMiddleware<TMiddleware>(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"No Invoke methods\")) { /* register differently or fix class */ }","preventionTips":["Follow the ASP.NET Core middleware convention (public instance Invoke/InvokeAsync returning Task/ValueTask)","Verify middleware classes after refactoring renames"],"tags":["middleware","reflection","pipeline"],"backgroundTag":"missing-required-argument","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}