elsa-workflows/elsa-core · error · InvalidOperationException
Invalid variable test values.
Error message
Invalid variable test values.
What it means
WorkflowDefinitionExtensions.GetVariableTestValues deserializes the definition's variable test values into IDictionary<string, object?>; if the payload is neither a dictionary nor a JSON object, it throws InvalidOperationException('Invalid variable test values.').
Solutions
- Fix the workflow definition so variable test values are a JSON object keyed by variable id
- Deserialize defensively and validate the shape before calling
- Catch InvalidOperationException and treat as an empty test-values set
Example fix
// before
var v = def.GetVariableTestValue(varId);
// after
IDictionary<string, object?> vals;
try { vals = def.GetVariableTestValues(); } catch (InvalidOperationException) { vals = new Dictionary<string, object?>(); }
var v = vals.TryGetValue(varId, out var x) ? x : null; Defensive patterns
Strategy: validation
Validate before calling
var raw = def.VariableTestValues; var ok = raw is IDictionary<string, object?> or (JsonElement e && e.ValueKind == JsonValueKind.Object);
Type guard
static bool IsValidTestValues(object? v) => v is IDictionary<string, object?> or JsonElement { ValueKind: JsonValueKind.Object }; Try / catch
try { values = def.GetVariableTestValues(); } catch (InvalidOperationException) { values = new Dictionary<string, object?>(); } Prevention
- Ensure variable test values are saved as JSON objects keyed by variable id
- Validate definitions after hand edits or migrations
- Guard reads with a shape check before calling
When it happens
Trigger: Calling GetVariableTestValues/GetVariableTestValue on a WorkflowDefinition whose VariableTestValues property is a JSON array, string, or other non-object shape.
Common situations: Hand-edited or migrated workflow definitions with malformed variable test values; API responses where the property was not a JSON object.
Related errors
- Cannot deserialize to .
- Failed to deserialize
- Failed to convert an object of type
- Invalid value type.
- Invalid target type.
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/ff726f87d024f383.
Report an issue: GitHub.
Appendix: source
Thrown at src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Extensions/WorkflowDefinitionExtensions.cs:22
namespace Elsa.Api.Client.Resources.WorkflowDefinitions.Extensions;
public static class WorkflowDefinitionExtensions
{
private const string VariableTestValuesKey = "VariableTestValues";
public static IDictionary<string, object?> GetVariableTestValues(this WorkflowDefinition workflowDefinition)
{
if (!workflowDefinition.CustomProperties.TryGetValue(VariableTestValuesKey, out var dictionary))
{
var testValues = new Dictionary<string, object?>();
workflowDefinition.CustomProperties[VariableTestValuesKey] = testValues;
return testValues;
}
if (dictionary is JsonElement jsonElement)
dictionary = JsonSerializer.Deserialize<Dictionary<string, object?>>(jsonElement.GetRawText());
return dictionary as IDictionary<string, object?> ?? throw new InvalidOperationException("Invalid variable test values.");
}
public static object? GetVariableTestValue(this WorkflowDefinition workflowDefinition, string variableId)
{
var testValues = workflowDefinition.GetVariableTestValues();
return testValues.TryGetValue(variableId, out var value) ? value : null;
}
public static void SetVariableTestValue(this WorkflowDefinition workflowDefinition, string variableId, object? value)
{
var testValues = workflowDefinition.GetVariableTestValues();
testValues[variableId] = value;
workflowDefinition.CustomProperties[VariableTestValuesKey] = testValues;
}
public static void ClearVariableTestValue(this WorkflowDefinition workflowDefinition, string variableId)
{
var testValues = workflowDefinition.GetVariableTestValues();View on GitHub (pinned to fe9217bdfa)