elsa-workflows/elsa-core · error · InvalidOperationException
Either ActivityTypeName or StimulusHash must be specified.
Error message
Either ActivityTypeName or StimulusHash must be specified.
What it means
DispatchStimulusCommandHandler dispatches a stimulus either by activity type name or by a precomputed stimulus hash. If neither ActivityTypeName nor StimulusHash is provided on the request, the handler cannot form a stimulus and throws InvalidOperationException.
Solutions
- Provide ActivityTypeName (with any stimulus data) or a StimulusHash on the request before dispatching.
- If you expected a hash, verify the upstream value that produced it (e.g. the bookmark's stimulus hash) is non-null and passed through.
- Add request validation at the API boundary to reject empty dispatch requests with a clear message.
Example fix
// before
await mediator.SendAsync(new DispatchStimulusCommand());
// after
await mediator.SendAsync(new DispatchStimulusCommand { ActivityTypeName = "HttpEndpoint", Stimulus = stimulus }); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(request.ActivityTypeName) && string.IsNullOrEmpty(request.StimulusHash))
throw new ArgumentException("Either ActivityTypeName or StimulusHash must be specified."); Try / catch
try { await mediator.SendAsync(command); } catch (InvalidOperationException ex) when (ex.Message.Contains("ActivityTypeName or StimulusHash")) { return BadRequest(ex.Message); } Prevention
- Validate dispatch requests at the API boundary before mediating
- Never construct DispatchStimulusCommand without stimulus identifiers
- Trace where StimulusHash originates and assert non-null upstream
- Model the request so at least one field is required by contract
When it happens
Trigger: Sending a dispatch stimulus request (e.g. via the API or an IDispatchStimulusCommand) with both ActivityTypeName and StimulusHash null/empty — e.g. a workflow caller forwarding a bookmark or payload that omitted both fields.
Common situations: API clients building the request payload manually and omitting fields; a null stimulus hash propagated from an upstream bookmark lookup that returned nothing; automation calling the endpoint with an empty body.
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
- A workflow definition handle must be provided.
- The specified activity is not part of the workflow.
- Workflow definition not found.
- Drain already in progress; second invocation rejected
- Drain already completed in this generation; subsequent…
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/83a8acd9bc784c8e.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Workflows.Runtime/Handlers/DispatchStimulusCommandHandler.cs:27
public class DispatchStimulusCommandHandler(IStimulusSender stimulusSender) : ICommandHandler<DispatchStimulusCommand>
{
public async Task<Unit> HandleAsync(DispatchStimulusCommand command, CancellationToken cancellationToken)
{
var request = command.Request;
if (request.ActivityTypeName != null)
{
await stimulusSender.SendAsync(request.ActivityTypeName, request.Stimulus!, request.Metadata, cancellationToken);
return Unit.Instance;
}
if (request.StimulusHash != null)
{
await stimulusSender.SendAsync(request.StimulusHash!, request.Metadata, cancellationToken);
return Unit.Instance;
}
throw new InvalidOperationException("Either ActivityTypeName or StimulusHash must be specified.");
}
}View on GitHub (pinned to fe9217bdfa)