{"record":{"id":"cb50334f66cd930e","repo":"elsa-workflows/elsa-core","slug":"not-a-primitive-type","errorCode":null,"errorMessage":"Not a primitive type.","messagePattern":"Not a primitive type\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Workflows.Core/Serialization/Converters/PolymorphicObjectConverter.cs","lineNumber":419,"sourceCode":"            return targetType;\n\n        if (SerializationTypeResolver.TryGetInstantiableCollectionType(targetType, out var instantiableCollectionType))\n            return instantiableCollectionType;\n\n        throw new JsonException($\"Workflow JSON type alias resolved to non-instantiable type '{targetType}'.\");\n    }\n\n    private static object ReadPrimitive(ref Utf8JsonReader reader, JsonSerializerOptions options)\n    {\n        return (reader.TokenType switch\n        {\n            JsonTokenType.True => true,\n            JsonTokenType.False => false,\n            JsonTokenType.Number when reader.TryGetInt64(out var l) => l,\n            JsonTokenType.Number => reader.GetDouble(),\n            JsonTokenType.String => reader.GetString(),\n            JsonTokenType.Null => null,\n            _ => throw new JsonException(\"Not a primitive type.\")\n        })!;\n    }\n\n    private object ReadObject(ref Utf8JsonReader reader, JsonSerializerOptions options)\n    {\n        switch (reader.TokenType)\n        {\n            case JsonTokenType.StartArray:\n                {\n                    var list = new List<object>();\n                    while (reader.Read())\n                    {\n                        switch (reader.TokenType)\n                        {\n                            default:\n                                list.Add(Read(ref reader, typeof(object), options));\n                                break;\n","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Workflows.Core/Serialization/Converters/PolymorphicObjectConverter.cs#L401-L437","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n{\"value\": } // malformed, empty value\n// after\n{\"value\": \"text\"}","handlingStrategy":"try-catch","validationCode":"// ensure well-formed JSON first\nusing var doc = JsonDocument.Parse(json); // throws on malformed JSON before Elsa deserialization","typeGuard":null,"tryCatchPattern":"try { var wf = JsonSerializer.Deserialize<WorkflowGraph>(json, options); }\ncatch (JsonException ex) { logger.LogError(ex, \"Workflow JSON is not a valid primitive at expected position\"); }","preventionTips":["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"],"tags":["json","deserialization","internal"],"backgroundTag":"json-parse-error","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}