elsa-workflows/elsa-core · error · InvalidOperationException
The memory block ' ' does not exist.
Error message
The memory block '{blockReference}' does not exist. What it means
ActivityExecutionContext.Get(MemoryBlockReference) throws InvalidOperationException when the referenced memory block does not exist in the workflow's memory register. Memory blocks back variables, arguments, and outputs; requesting a block that was never registered (or was removed) fails fast instead of returning a misleading null.
Solutions
- Ensure the variable/output is declared in a scope enclosing the activity calling Get, so its memory block is registered.
- Compare the block reference Id in the message against declared variables/outputs in the definition.
- Use context.TryGet(blockReference, out var value) when absence is an expected condition.
- If resuming persisted instances, verify the memory store contains the block (persistence provider configured correctly).
Example fix
// before
var value = context.Get(myVariable); // throws if block absent
// after
if (context.TryGet(myVariable, out var value))
{
// use value
}
else
{
value = defaultValue;
} Defensive patterns
Strategy: type-guard
Validate before calling
// check the block exists before reading
if (context.TryGet(blockReference, out var existing))
{
// safe to use existing
} Type guard
bool TryGetMemoryBlock(ActivityExecutionContext context, MemoryBlockReference reference, out object? value) => context.TryGet(reference, out value);
Try / catch
try { var value = context.Get(myVariable); }
catch (InvalidOperationException ex) when (ex.Message.Contains("does not exist"))
{
logger.LogWarning(ex, "Memory block {Id} missing; using default", myVariable.Id);
value = defaultValue;
} Prevention
- Prefer TryGet when absence is a legitimate outcome.
- Declare variables in a scope enclosing every activity that reads them.
- Ensure outputs are produced before consumers read them (respect control-flow edges).
- Verify persistence restores memory blocks when resuming instances.
When it happens
Trigger: Calling context.Get(someVariable) or context.Get(output) where the variable/output's MemoryBlockReference was never allocated — the variable is not declared in scope, the block belongs to a different scope, or the reference ID is stale.
Common situations: Reading an output of an activity that never executed (block not yet created); referencing a deleted/renamed variable; a child activity reading a sibling scope's variable; resuming an instance whose memory was not persisted/restored.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- AlterationFaultCodes.PlanNotFound
- Activity type not found
- Variable ' ' not found.
- Workflow definition not found.
- Workflow instance not found.
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/cc051d34f37d4d6a.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs:708
public T? Get<T>(Output<T>? output) => output == null ? default : Get<T>(output.MemoryBlockReference());
/// <summary>
/// Gets the value of the specified output.
/// </summary>
/// <param name="output">The output.</param>
/// <returns>The output value.</returns>
public object? Get(Output? output) => output == null ? null : Get(output.MemoryBlockReference());
/// <summary>
/// Gets the value of the specified memory block.
/// </summary>
/// <param name="blockReference">The memory block reference.</param>
/// <returns>The memory block value.</returns>
/// <exception cref="InvalidOperationException">The memory block does not exist.</exception>
public object? Get(MemoryBlockReference blockReference)
{
return !TryGet(blockReference, out var value)
? throw new InvalidOperationException($"The memory block '{blockReference}' does not exist.")
: value;
}
/// <summary>
/// Gets the value of the specified memory block.
/// </summary>
/// <param name="blockReference">The memory block reference.</param>
/// <typeparam name="T">The type of the memory block.</typeparam>
/// <returns>The memory block value.</returns>
public T? Get<T>(MemoryBlockReference blockReference)
{
var value = Get(blockReference);
return value != null ? value.ConvertTo<T>() : default;
}
/// <summary>
/// Tries to get the value of the specified memory block.
/// </summary>View on GitHub (pinned to fe9217bdfa)