elsa-workflows/elsa-core · error · InvalidOperationException
No Invoke methods were found. Use either Invoke or…
Error message
No Invoke methods were found. Use either Invoke or InvokeAsync
What it means
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).
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
Example fix
// before
public class MyMiddleware { public Task HandleAsync(Context ctx) => Next(ctx); }
// after
public class MyMiddleware { public Task InvokeAsync(Context ctx) => Next(ctx); } Defensive patterns
Strategy: validation
Validate before calling
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."); Try / catch
try { pipelines.UseMiddleware<TMiddleware>(); } catch (InvalidOperationException ex) when (ex.Message.Contains("No Invoke methods")) { /* register differently or fix class */ } Prevention
- Follow the ASP.NET Core middleware convention (public instance Invoke/InvokeAsync returning Task/ValueTask)
- Verify middleware classes after refactoring renames
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Multiple Invoke methods were found. Use either Invoke or…
- No Invoke methods were found. Use either Invoke or…
- Multiple Invoke methods were found. Use either Invoke or…
- The method must return Task or ValueTask
- The method must return Task or ValueTask
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/4c9da8edada50a32.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Workflows.Core/Pipelines/MiddlewareHelpers.cs:19
using System.Reflection;
namespace Elsa.Workflows.Pipelines;
public static class MiddlewareHelpers
{
public static MethodInfo GetInvokeMethod(Type middleware)
{
const string invokeMethodName = "Invoke";
const string invokeAsyncMethodName = "InvokeAsync";
var methods = middleware.GetMethods(BindingFlags.Instance | BindingFlags.Public);
var invokeMethods = methods.Where(m => string.Equals(m.Name, invokeMethodName, StringComparison.Ordinal) || string.Equals(m.Name, invokeAsyncMethodName, StringComparison.Ordinal)).ToArray();
switch (invokeMethods.Length)
{
case > 1:
throw new InvalidOperationException("Multiple Invoke methods were found. Use either Invoke or InvokeAsync.");
case 0:
throw new InvalidOperationException("No Invoke methods were found. Use either Invoke or InvokeAsync");
}
var methodInfo = invokeMethods[0];
if (!typeof(Task).IsAssignableFrom(methodInfo.ReturnType) && !typeof(ValueTask).IsAssignableFrom(methodInfo.ReturnType))
throw new InvalidOperationException($"The {methodInfo.Name} method must return Task or ValueTask");
return methodInfo;
}
}View on GitHub (pinned to fe9217bdfa)