elsa-workflows/elsa-core · error · JsonException
Not a primitive type.
Error message
Not a primitive type.
What it means
ReadPrimitive in PolymorphicObjectConverter throws this when the current JSON token is not one of the primitive tokens it handles (True, False, Number, String, Null). Anything else (StartObject, StartArray, EndObject, PropertyName, None) falls through to the default case. It is an internal guard during polymorphic deserialization of untyped values.
Solutions
- Validate/repair the JSON payload so primitives appear where expected (a JSON linter catches truncated or misplaced values)
- Confirm the serializer is always positioned on a value token before calling Read; do not manually advance the Utf8JsonReader past a value
- If it persists on valid JSON, file a bug — this is an internal invariant of the converter
Example fix
// before
{"value": } // malformed, empty value
// after
{"value": "text"} Defensive patterns
Strategy: try-catch
Validate before calling
// ensure well-formed JSON first using var doc = JsonDocument.Parse(json); // throws on malformed JSON before Elsa deserialization
Try / catch
try { var wf = JsonSerializer.Deserialize<WorkflowGraph>(json, options); }
catch (JsonException ex) { logger.LogError(ex, "Workflow JSON is not a valid primitive at expected position"); } Prevention
- Validate JSON payload with a strict parser before deserializing
- Never hand-advance the Utf8JsonReader before handing it to the serializer
- Avoid hand-editing serialized workflow definitions
When it happens
Trigger: JSON payload contains an object or array at a position where ReadPrimitive is called with a token such as JsonTokenType.StartObject, StartArray, PropertyName, or None — typically malformed or truncated JSON, or reader state advanced unexpectedly.
Common situations: Hand-edited or truncated workflow JSON; a serializer bug where reader state is out of sync; feeding non-JSON or partially consumed Utf8JsonReader into workflow deserialization.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- Unknown token
- Cannot convert to bool
- Cannot convert to bool?
- Cannot deserialize to .
- Expected a metadata property name.
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/cb50334f66cd930e.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Workflows.Core/Serialization/Converters/PolymorphicObjectConverter.cs:419
return targetType;
if (SerializationTypeResolver.TryGetInstantiableCollectionType(targetType, out var instantiableCollectionType))
return instantiableCollectionType;
throw new JsonException($"Workflow JSON type alias resolved to non-instantiable type '{targetType}'.");
}
private static object ReadPrimitive(ref Utf8JsonReader reader, JsonSerializerOptions options)
{
return (reader.TokenType switch
{
JsonTokenType.True => true,
JsonTokenType.False => false,
JsonTokenType.Number when reader.TryGetInt64(out var l) => l,
JsonTokenType.Number => reader.GetDouble(),
JsonTokenType.String => reader.GetString(),
JsonTokenType.Null => null,
_ => throw new JsonException("Not a primitive type.")
})!;
}
private object ReadObject(ref Utf8JsonReader reader, JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case JsonTokenType.StartArray:
{
var list = new List<object>();
while (reader.Read())
{
switch (reader.TokenType)
{
default:
list.Add(Read(ref reader, typeof(object), options));
break;
View on GitHub (pinned to fe9217bdfa)