elsa-workflows/elsa-core · error · NotSupportedException
Cannot deserialize to .
Error message
Cannot deserialize {value.GetType()} to {typeof(T)}. What it means
JsonObjectExtensions.GetNullableValue/GetValue-like conversion helper in Elsa.Api.Client throws NotSupportedException when a JSON node value cannot be converted to the requested type T. The helper handles enums, JsonValue nodes, strings, and a few primitives; any other JsonNode subtype (e.g. JsonObject or JsonArray) falls through to this throw.
Solutions
- Check the JsonNode kind before calling (ValueKind / is JsonObject, is JsonArray) and use JsonSerializer.Deserialize<T> for object/array nodes
- Change T to a matching type (e.g. Dictionary<string,object>, JsonElement)
- Wrap in try-catch (NotSupportedException) and provide a default
Example fix
// before
var count = json.GetPropertyOrDefault<int>("customProps");
// after
var props = json.GetPropertyOrDefault<Dictionary<string, object?>>("customProps"); Defensive patterns
Strategy: type-guard
Validate before calling
var node = json["prop"];
if (node is not (JsonValue or null)) throw new InvalidOperationException("Expected a scalar JSON value"); Type guard
static bool IsScalarJsonNode(JsonNode? n) => n is JsonValue or null;
Try / catch
try { value = json.GetPropertyOrDefault<T>(name); } catch (NotSupportedException) { value = default; } Prevention
- Check node kind (is JsonObject/is JsonArray) before scalar conversion
- Match T to the actual JSON value shape
- Keep client property types in sync with workflow definition schemas
When it happens
Trigger: Calling the extension with T that does not match the underlying JSON value, e.g. the property is a nested object or array (JsonObject/JsonArray) but T is a primitive like int or string.
Common situations: Reading custom properties from workflow definitions where a value is a dictionary or list but the client code tries to read it as a scalar; schema drift between Studio-created properties and client expectations.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Failed to deserialize
- Expected a string tag.
- Expected a string metadata value.
- Invalid variable test values.
- The binding to activity type
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/8fdaf801a187ad06.
Report an issue: GitHub.
Appendix: source
Thrown at src/clients/Elsa.Api.Client/Extensions/JsonObjectExtensions.cs:90
options ??= new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
if (value is JsonObject jsonObject)
return JsonSerializer.Deserialize<T>(jsonObject, options)!;
if (value is JsonArray jsonArray)
return JsonSerializer.Deserialize<T>(jsonArray, options)!;
if (typeof(T).IsEnum || (Nullable.GetUnderlyingType(typeof(T))?.IsEnum ?? false))
{
if (value.GetValueKind() == JsonValueKind.Null)
return default!;
return (T)Enum.Parse(Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T), value.ToString());
}
if (value is JsonValue jsonValue)
return jsonValue.GetValue<T>();
throw new NotSupportedException($"Cannot deserialize {value.GetType()} to {typeof(T)}.");
}
/// <summary>
/// Sets the property value of the specified model.
/// </summary>
/// <param name="model">The model to set the property value on.</param>
/// <param name="value">The value to set.</param>
/// <param name="path">The path to the property.</param>
public static void SetProperty(this JsonObject model, JsonNode? value, params string[] path)
{
model = GetPropertyContainer(model, path);
model[path.Last()] = value?.SerializeToNode();
}
/// <summary>
/// Sets the property value of the specified model.
/// </summary>
/// <param name="model">The model to set the property value on.</param>View on GitHub (pinned to fe9217bdfa)