{"record":{"id":"97c635ff255d8b69","repo":"elsa-workflows/elsa-core","slug":"unknown-token-reader-tokentype","errorCode":null,"errorMessage":"Unknown token {reader.TokenType}","messagePattern":"Unknown token (.+?)","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Workflows.Core/Serialization/Converters/ExpandoObjectConverter.cs","lineNumber":82,"sourceCode":"                {\n                    switch (reader.TokenType)\n                    {\n                        case JsonTokenType.EndObject:\n                            return dict;\n                        case JsonTokenType.PropertyName:\n                            var key = reader.GetString()!;\n                            reader.Read();\n                            var value = Read(ref reader, typeof(object), options)!;\n                            dict.Add(key, value);\n                            break;\n                        default:\n                            throw new JsonException();\n                    }\n                }\n\n                throw new JsonException();\n            default:\n                throw new JsonException($\"Unknown token {reader.TokenType}\");\n        }\n    }\n\n    private IDictionary<string, object> CreateDictionary() => new ExpandoObject()!;\n}","sourceCodeStart":64,"sourceCodeEnd":87,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Workflows.Core/Serialization/Converters/ExpandoObjectConverter.cs#L64-L87","documentation":"ExpandoObjectConverter.Read deserializes JSON into an IDictionary<string,object> backed by ExpandoObject, handling only the token types it knows (StartObject, StartArray, primitives, etc.). If the reader lands on a JsonTokenType it does not handle (default branch), it throws JsonException(\"Unknown token ...\"). This indicates malformed or structurally unexpected JSON.","triggerScenarios":"Deserializing a property dictionary where the reader is positioned on an unexpected token such as PropertyName, EndObject, or None — typically malformed nesting or a value appearing where a key was expected (src/modules/Elsa.Workflows.Core/Serialization/Converters/ExpandoObjectConverter.cs:82).","commonSituations":"Corrupted workflow instance state JSON; deserializing JSON with duplicate/misnested keys; feeding JSON5-style content into a strict System.Text.Json reader.","solutions":["Validate the JSON structure of the property/state payload before deserialization.","Fix misnested braces/keys in the JSON source.","Re-materialize the payload from a trusted export (Studio or workflow export API).","If a custom converter chains into this one, verify the reader position it hands over is on a supported token."],"exampleFix":"// before (invalid: object used as key position)\n{ [\"key\"]: \"value\" }\n\n// after\n{ \"key\": \"value\" }","handlingStrategy":"validation","validationCode":"using var doc = JsonDocument.Parse(json);\nif (doc.RootElement.ValueKind == JsonValueKind.Array || doc.RootElement.ValueKind == JsonValueKind.String)\n    throw new InvalidOperationException(\"Expected a JSON object for property dictionary\");","typeGuard":"static bool IsJsonObject(string s) { try { using var d = JsonDocument.Parse(s); return d.RootElement.ValueKind == JsonValueKind.Object; } catch { return false; } }","tryCatchPattern":"try { var props = JsonSerializer.Deserialize<IDictionary<string, object>>(json, options); } catch (JsonException ex) when (ex.Message.StartsWith(\"Unknown token\")) { log.LogError(ex, \"Unexpected token in property dictionary JSON\"); }","preventionTips":["Keep property/state payloads strictly as key/value JSON objects","Avoid feeding JSON5 or comment-bearing JSON into strict System.Text.Json","Detect and repair corrupted instance state blobs before deserialization"],"tags":["csharp","json","expandoobject","serialization"],"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-15T23:17:13.987Z"}