elsa-workflows/elsa-core · error · Exception
Failed to deserialize
Error message
Failed to deserialize {stringValue} to {underlyingTargetType} What it means
ObjectConverter.ConvertTo wraps JsonSerializer.Deserialize failures in a generic Exception with a message showing the string and target type. It is thrown when a JSON-looking string ('{' or '[' prefixed) cannot be deserialized to the underlying target type.
Solutions
- Validate the string is well-formed JSON of the expected shape before conversion
- Fix the stored value so it matches the target type schema
- Catch Exception around ConvertTo and log stringValue for diagnosis, then supply a fallback
Example fix
// before
var options = ObjectConverter.ConvertTo<MyOptions>(rawString);
// after
MyOptions options;
try { options = ObjectConverter.ConvertTo<MyOptions>(rawString); }
catch (Exception e) { logger.LogError(e, "Bad value: {V}", rawString); options = new MyOptions(); } Defensive patterns
Strategy: try-catch
Validate before calling
if (s.TrimStart().StartsWith('{') || s.TrimStart().StartsWith('['))
using (var doc = JsonDocument.Parse(s)) { /* shape check */ } Try / catch
try { result = ObjectConverter.ConvertTo<T>(s); } catch (Exception e) { logger.LogError(e, "Convert failed for: {Value}", s); result = default; } Prevention
- Validate stored JSON strings parse before conversion
- Verify target type matches the JSON shape
- Version-check workflow definitions after schema migrations
When it happens
Trigger: Calling ConvertTo<T> (or via activity property conversion) with a string value that starts with '{' or '[' whose content is not valid JSON or does not match the target type shape.
Common situations: Workflow input/property values stored as JSON strings in definitions; malformed JSON saved by designers or hand-edited definitions; target type changed between versions.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- Cannot deserialize to .
- Invalid variable test values.
- The binding to activity type
- Expected number or string.
- Cannot convert to bool
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/3dd739f813bd14e5.
Report an issue: GitHub.
Appendix: source
Thrown at src/clients/Elsa.Api.Client/Extensions/ObjectConverter.cs:83
}
if (value is JsonNode jsonNode)
return jsonNode.Deserialize(targetType, options);
if (underlyingSourceType == typeof(string) && !underlyingTargetType.IsPrimitive && underlyingTargetType != typeof(object))
{
var stringValue = (string)value;
try
{
var firstChar = stringValue.TrimStart().FirstOrDefault();
if (firstChar is '{' or '[')
return JsonSerializer.Deserialize(stringValue, underlyingTargetType, options);
}
catch (Exception)
{
throw new Exception($"Failed to deserialize {stringValue} to {underlyingTargetType}");
}
}
if (targetType == typeof(object))
return value;
if (underlyingTargetType.IsInstanceOfType(value))
return value;
if (underlyingSourceType == underlyingTargetType)
return value;
if (IsDateType(underlyingSourceType) && IsDateType(underlyingTargetType))
return ConvertAnyDateType(value, underlyingTargetType);
if (typeof(IDictionary<string, object>).IsAssignableFrom(underlyingSourceType) && underlyingTargetType.IsClass)
{
if (typeof(ExpandoObject) == underlyingTargetType)View on GitHub (pinned to fe9217bdfa)