{"record":{"id":"536d2f46697a3606","repo":"ElectronNET/Electron.NET","slug":"unexpected-end-while-reading-array","errorCode":null,"errorMessage":"Unexpected end while reading array.","messagePattern":"Unexpected end while reading array\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/ElectronNET.API/Serialization/JsonToBoxedPrimitivesConverter.cs","lineNumber":58,"sourceCode":"                        obj[name] = ReadValue(ref r);\n                    }\n\n                    throw new JsonException(\"Unexpected end while reading object.\");\n\n                case JsonTokenType.StartArray:\n\n                    var list = new List<object>();\n                    while (r.Read())\n                    {\n                        if (r.TokenType == JsonTokenType.EndArray)\n                        {\n                            return list;\n                        }\n\n                        list.Add(ReadValue(ref r));\n                    }\n\n                    throw new JsonException(\"Unexpected end while reading array.\");\n\n                case JsonTokenType.True: return true;\n                case JsonTokenType.False: return false;\n                case JsonTokenType.Null: return null;\n\n                case JsonTokenType.Number:\n\n                    if (r.TryGetInt32(out int i))\n                    {\n                        return i;\n                    }\n\n                    if (r.TryGetInt64(out long l))\n                    {\n                        return l;\n                    }\n\n                    if (r.TryGetDouble(out double d))","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/ElectronNET/Electron.NET/blob/87cc6f98b6a9c5968d7846c0e775ea713bd0d7b2/src/ElectronNET.API/Serialization/JsonToBoxedPrimitivesConverter.cs#L40-L76","documentation":"JsonToBoxedPrimitivesConverter.ReadValue, when parsing a JSON array into a List<object>, throws this JsonException if the reader is exhausted before the EndArray token is reached. It signals the JSON stream ended while still inside an array.","triggerScenarios":"An array missing its closing bracket, e.g. '[1, 2, 3' with no ']', or the stream ending mid-array during IPC transmission.","commonSituations":"Truncated IPC payloads; building arrays via string concatenation and dropping the closing bracket; incomplete reads from a stream.","solutions":["Close all arrays with ']' and validate the JSON before sending","Check the transport layer for truncation of large payloads","Log the raw payload on failure to locate the cut point","Round-trip through JSON.parse on the sender to catch malformed output"],"exampleFix":"// before\nvar json = \"[1, 2, 3\"; // missing ]\n// after\nvar json = \"[1, 2, 3]\";","handlingStrategy":"try-catch","validationCode":"bool isCompleteArray(string json) =>\n    json.TrimStart().StartsWith(\"[\") && json.TrimEnd().EndsWith(\"]\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var value = JsonSerializer.Deserialize<object>(json, ElectronJson.Options);\n}\ncatch (JsonException ex)\n{\n    logger.LogWarning(ex, \"Incomplete JSON array: {Raw}\", json);\n}","preventionTips":["Serialize arrays with JSON.stringify instead of manual string building","Ensure transports don't truncate large arrays","Round-trip JSON.parse on the sender to validate output"],"tags":["json","parsing","truncated"],"backgroundTag":"json-parse-error","analyzedSha":"87cc6f98b6a9c5968d7846c0e775ea713bd0d7b2","analyzedAt":"2026-09-14T03:09:47.608Z","contentChangedAt":"2026-09-14T03:09:47.608Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}