diff --git a/src/modules/Elsa.Expressions/Helpers/ObjectConverter.cs b/src/modules/Elsa.Expressions/Helpers/ObjectConverter.cs index 93a0b2a77..7bb35b1b4 100644 --- a/src/modules/Elsa.Expressions/Helpers/ObjectConverter.cs +++ b/src/modules/Elsa.Expressions/Helpers/ObjectConverter.cs @@ -104,7 +104,7 @@ public static class ObjectConverter return underlyingTargetType switch { { } t when t == typeof(string) => jsonNode.ToString(), - { } t when t == typeof(ExpandoObject) => JsonSerializer.Deserialize(jsonNode.ToJsonString()), + { } t when t == typeof(ExpandoObject) && jsonNode.GetValueKind() == JsonValueKind.Object => JsonSerializer.Deserialize(jsonNode.ToJsonString()), { } t when t != typeof(object) || converterOptions?.DeserializeJsonObjectToObject == true => jsonNode.Deserialize(targetType, serializerOptions), _ => jsonNode }; diff --git a/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs b/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs index 3b351eddf..2ca6dcc86 100644 --- a/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs +++ b/src/modules/Elsa.Workflows.Core/Services/VariablePersistenceManager.cs @@ -40,18 +40,26 @@ public class VariablePersistenceManager(IStorageDriverManager storageDriverManag continue; var id = GetStateId(variable); - var value = await driver.ReadAsync(id, storageDriverContext); - if (value == null) continue; - register.Declare(variable); - - if (!variable.TryParseValue(value, out var parsedValue)) + try { - logger.LogWarning("Failed to parse value for variable {VariableId} of type {VariableType} with value {Value}", variable.Id, variable.GetVariableType().FullName, value); - continue; - } + var value = await driver.ReadAsync(id, storageDriverContext); + if (value == null) continue; - variable.Set(register, parsedValue); + register.Declare(variable); + + if (!variable.TryParseValue(value, out var parsedValue)) + { + logger.LogWarning("Failed to parse value for variable {VariableId} of type {VariableType} with value {Value}", variable.Id, variable.GetVariableType().FullName, value); + continue; + } + + variable.Set(register, parsedValue); + } + catch (Exception e) + { + logger.LogError(e, "Failed to read variable {VariableId} from storage driver {StorageDriverType}", variable.Id, driver.GetType().FullName); + } } } }