{"record":{"id":"cc051d34f37d4d6a","repo":"elsa-workflows/elsa-core","slug":"the-memory-block-blockreference-does-not-exist","errorCode":null,"errorMessage":"The memory block '{blockReference}' does not exist.","messagePattern":"The memory block '(.+?)' does not exist\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs","lineNumber":708,"sourceCode":"    public T? Get<T>(Output<T>? output) => output == null ? default : Get<T>(output.MemoryBlockReference());\n\n    /// <summary>\n    /// Gets the value of the specified output.\n    /// </summary>\n    /// <param name=\"output\">The output.</param>\n    /// <returns>The output value.</returns>\n    public object? Get(Output? output) => output == null ? null : Get(output.MemoryBlockReference());\n\n    /// <summary>\n    /// Gets the value of the specified memory block.\n    /// </summary>\n    /// <param name=\"blockReference\">The memory block reference.</param>\n    /// <returns>The memory block value.</returns>\n    /// <exception cref=\"InvalidOperationException\">The memory block does not exist.</exception>\n    public object? Get(MemoryBlockReference blockReference)\n    {\n        return !TryGet(blockReference, out var value)\n            ? throw new InvalidOperationException($\"The memory block '{blockReference}' does not exist.\")\n            : value;\n    }\n\n    /// <summary>\n    /// Gets the value of the specified memory block.\n    /// </summary>\n    /// <param name=\"blockReference\">The memory block reference.</param>\n    /// <typeparam name=\"T\">The type of the memory block.</typeparam>\n    /// <returns>The memory block value.</returns>\n    public T? Get<T>(MemoryBlockReference blockReference)\n    {\n        var value = Get(blockReference);\n        return value != null ? value.ConvertTo<T>() : default;\n    }\n\n    /// <summary>\n    /// Tries to get the value of the specified memory block.\n    /// </summary>","sourceCodeStart":690,"sourceCodeEnd":726,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs#L690-L726","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nvar value = context.Get(myVariable); // throws if block absent\n// after\nif (context.TryGet(myVariable, out var value))\n{\n    // use value\n}\nelse\n{\n    value = defaultValue;\n}","handlingStrategy":"type-guard","validationCode":"// check the block exists before reading\nif (context.TryGet(blockReference, out var existing))\n{\n    // safe to use existing\n}","typeGuard":"bool TryGetMemoryBlock(ActivityExecutionContext context, MemoryBlockReference reference, out object? value) => context.TryGet(reference, out value);","tryCatchPattern":"try { var value = context.Get(myVariable); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"does not exist\"))\n{\n    logger.LogWarning(ex, \"Memory block {Id} missing; using default\", myVariable.Id);\n    value = defaultValue;\n}","preventionTips":["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."],"tags":["workflow","memory","variable","not-found"],"backgroundTag":"resource-not-found","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"}