{"record":{"id":"ff726f87d024f383","repo":"elsa-workflows/elsa-core","slug":"invalid-variable-test-values","errorCode":null,"errorMessage":"Invalid variable test values.","messagePattern":"Invalid variable test values\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Extensions/WorkflowDefinitionExtensions.cs","lineNumber":22,"sourceCode":"namespace Elsa.Api.Client.Resources.WorkflowDefinitions.Extensions;\n\npublic static class WorkflowDefinitionExtensions\n{\n    private const string VariableTestValuesKey = \"VariableTestValues\";\n\n    public static IDictionary<string, object?> GetVariableTestValues(this WorkflowDefinition workflowDefinition)\n    {\n        if (!workflowDefinition.CustomProperties.TryGetValue(VariableTestValuesKey, out var dictionary))\n        {\n            var testValues = new Dictionary<string, object?>();\n            workflowDefinition.CustomProperties[VariableTestValuesKey] = testValues;\n            return testValues;\n        }\n\n        if (dictionary is JsonElement jsonElement)\n            dictionary = JsonSerializer.Deserialize<Dictionary<string, object?>>(jsonElement.GetRawText());\n\n        return dictionary as IDictionary<string, object?> ?? throw new InvalidOperationException(\"Invalid variable test values.\");\n    }\n\n    public static object? GetVariableTestValue(this WorkflowDefinition workflowDefinition, string variableId)\n    {\n        var testValues = workflowDefinition.GetVariableTestValues();\n        return testValues.TryGetValue(variableId, out var value) ? value : null;\n    }\n\n    public static void SetVariableTestValue(this WorkflowDefinition workflowDefinition, string variableId, object? value)\n    {\n        var testValues = workflowDefinition.GetVariableTestValues();\n        testValues[variableId] = value;\n        workflowDefinition.CustomProperties[VariableTestValuesKey] = testValues;\n    }\n\n    public static void ClearVariableTestValue(this WorkflowDefinition workflowDefinition, string variableId)\n    {\n        var testValues = workflowDefinition.GetVariableTestValues();","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Extensions/WorkflowDefinitionExtensions.cs#L4-L40","documentation":"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.').","triggerScenarios":"Calling GetVariableTestValues/GetVariableTestValue on a WorkflowDefinition whose VariableTestValues property is a JSON array, string, or other non-object shape.","commonSituations":"Hand-edited or migrated workflow definitions with malformed variable test values; API responses where the property was not a JSON object.","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"],"exampleFix":"// before\nvar v = def.GetVariableTestValue(varId);\n// after\nIDictionary<string, object?> vals;\ntry { vals = def.GetVariableTestValues(); } catch (InvalidOperationException) { vals = new Dictionary<string, object?>(); }\nvar v = vals.TryGetValue(varId, out var x) ? x : null;","handlingStrategy":"validation","validationCode":"var raw = def.VariableTestValues;\nvar ok = raw is IDictionary<string, object?> or (JsonElement e && e.ValueKind == JsonValueKind.Object);","typeGuard":"static bool IsValidTestValues(object? v) => v is IDictionary<string, object?> or JsonElement { ValueKind: JsonValueKind.Object };","tryCatchPattern":"try { values = def.GetVariableTestValues(); } catch (InvalidOperationException) { values = new Dictionary<string, object?>(); }","preventionTips":["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"],"tags":["dotnet","workflow-definitions","json"],"backgroundTag":"unexpected-response-shape","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"}