Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

Version 3.5.2 removed code that handled Literal objects in ActivityExecutionContext.TryGet(), breaking the common pattern of programmatically creating activities with literal inputs. This throws InvalidOperationException: The memory block 'Elsa.Expressions.Models.Literal1[T]' does not exist.`

Root Cause

When Input<T> is constructed with a Literal, the literal becomes the MemoryBlockReference. Unlike variables, literals hold values directly rather than storing them in the memory register. Without special handling, TryGet attempts to look up the literal in the register and fails.

Changes

  • Restored literal check in ActivityExecutionContext.TryGet(): Added early return when blockReference is Literal to retrieve the value directly
  • Added test coverage: Integration test reproducing the reported issue, unit tests validating literal behavior
public bool TryGet(MemoryBlockReference blockReference, out object? value)
{
    if (blockReference is Literal literal)
    {
        value = literal.Value;
        return true;
    }
    // ... existing lookup logic
}

Use Case

Activities that dynamically instantiate and configure other activities with literal values:

var activity = new SetVariable
{
    Variable = myVar,
    Value = new Input<string>(new Literal<string>("constant value"))
};
// Accessing the input now works instead of throwing
Original prompt

This section details on the original issue you should resolve

<issue_title>ActivityExecutionContext doesn't handle dynamic Literal's anymore</issue_title>
<issue_description>## Description
In version 3.5.2 the code fragment
if (blockReference is Literal literal)
{
value = literal.Value;
return true;
}
Is removed in ActivityExecutionContext:TryGet(MemoryBlockReference blockReference)

Steps to Reproduce

We have a Activity that re-uses an other activity execute method by creating an instance and setting the inputs of that activity with literals. Since 3.5.2 this fails because Get cannot find the memory block

System.InvalidOperationException
HResult=0x80131509
Message=The memory block 'Elsa.Expressions.Models.Literal1[System.Object]' does not exist. Source=Elsa.Workflows.Core StackTrace: at Elsa.Workflows.ActivityExecutionContext.Get(MemoryBlockReference blockReference) in /_/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs:line 726 at Elsa.Workflows.ActivityExecutionContext.Get[T](MemoryBlockReference blockReference) in /_/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs:line 739 at Elsa.Workflows.ActivityExecutionContext.Get[T](Input1 input) in /_/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs:line 701</issue_description>

<agent_instructions>See if you can gather some more context to understand the removal of the mentioned code, and what the consequence might be to put it back.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@sfmskywalker I'm not 100% sure, but I usually have a reason to remove things. But, it's always possible I have't considered enough angles. Would you be able to provide steps to reproduce?

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


This change is Reviewable

This restores support for dynamic Literal inputs that was removed in version 3.5.2.
When an Input is created with a Literal, the Literal becomes the MemoryBlockReference.
Since Literals hold values directly rather than in the memory register, they need
special handling in TryGet to return their value.

Co-authored-by: sfmskywalker <[email protected]>
Copilot AI changed the title [WIP] Fix ActivityExecutionContext to handle dynamic Literals Restore Literal handling in ActivityExecutionContext.TryGet Nov 19, 2025
Copilot AI requested a review from sfmskywalker November 19, 2025 19:48
Copilot finished work on behalf of sfmskywalker November 19, 2025 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants