{"record":{"id":"4109447dfacfa0aa","repo":"JamesNK/Newtonsoft.Json","slug":"the-jsonreader-should-not-be-on-a-token-of-type-0","errorCode":null,"errorMessage":"The JsonReader should not be on a token of type {0}.","messagePattern":"The JsonReader should not be on a token of type (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JContainer.Async.cs","lineNumber":165,"sourceCode":"                        break;\n                    case JsonToken.Undefined:\n                        v = JValue.CreateUndefined();\n                        v.SetLineInfo(lineInfo, settings);\n                        parent.Add(v);\n                        break;\n                    case JsonToken.PropertyName:\n                        JProperty? property = ReadProperty(reader, settings, lineInfo, parent);\n                        if (property != null)\n                        {\n                            parent = property;\n                        }\n                        else\n                        {\n                            await reader.SkipAsync().ConfigureAwait(false);\n                        }\n                        break;\n                    default:\n                        throw new InvalidOperationException(\"The JsonReader should not be on a token of type {0}.\".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));\n                }\n            } while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false));\n        }\n    }\n}\n\n#endif\n","sourceCodeStart":147,"sourceCodeEnd":173,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JContainer.Async.cs#L147-L173","documentation":"Thrown by the async ReadContentFromAsync default switch case when the JsonReader is positioned on a token type the loader does not handle. The loader covers the standard JSON tokens; any other/unexpected token type is an invalid reader state.","triggerScenarios":"Using a custom JsonReader subclass that returns a novel or out-of-range JsonToken value; an async Load (e.g. JArray.LoadAsync) over a reader left in a bad state.","commonSituations":"Third-party/custom readers; corrupt or hand-advanced reader state; version skew between reader and library.","solutions":["Use the built-in JsonTextReader over well-formed JSON input.","Do not manually advance the reader before calling the async Load; let the loader drive reads.","If using a custom reader, ensure it only yields standard JsonToken values and starts at None/StartArray/StartObject."],"exampleFix":"// before\nvar jArr = await JArray.LoadAsync(myPartlyConsumedReader);\n// after\nusing var reader = new JsonTextReader(new StringReader(jsonText));\nvar jArr = await JArray.LoadAsync(reader);","handlingStrategy":"try-catch","validationCode":"if (!(reader is JsonTextReader)) {\n    // ensure reader is positioned at a valid start token before async load\n    reader.MoveToContent();\n}","typeGuard":null,"tryCatchPattern":"try { var token = await JArray.LoadAsync(reader); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"should not be on a token of type\")) {\n    // reader is in a bad state; re-create a JsonTextReader from the source text\n}","preventionTips":["Use JsonTextReader over well-formed JSON for async loads.","Don't manually advance the reader before LoadAsync.","Avoid custom JsonReader subclasses that emit non-standard token types."],"tags":["jsonreader","async","invalid-operation","parsing"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}