ElectronNET/Electron.NET · error · JsonException
Unexpected token when reading releaseNotes.
Error message
Unexpected token {reader.TokenType} when reading releaseNotes. What it means
ReleaseNotesConverter.Read throws this JsonException when it encounters a JSON token it does not handle while deserializing an Electron releaseNotes value (expected null, a single object, or an array of objects). The converter hits the default switch branch, meaning the incoming payload shape does not match any expected case.
Solutions
- Check the actual JSON payload being sent for releaseNotes and make it either null, an object, or an array of objects
- Ensure ElectronNET.Host and ElectronNET.API package versions match so payload shapes agree
- Inspect reader.TokenType in a debugger or log to identify the unexpected token type
- If the payload is a string, parse or wrap it before deserialization
Example fix
// before
{ "releaseNotes": "Bug fixes and improvements" }
// after
{ "releaseNotes": [{ "version": "1.0.1", "notes": "Bug fixes and improvements" }] } Defensive patterns
Strategy: try-catch
Validate before calling
// validate shape before deserializing
using var doc = JsonDocument.Parse(rawJson);
var t = doc.RootElement.GetProperty("releaseNotes").ValueKind;
bool ok = t == JsonValueKind.Null || t == JsonValueKind.Array || t == JsonValueKind.Object; Type guard
bool IsValidReleaseNotes(JsonElement e) =>
e.ValueKind is JsonValueKind.Null or JsonValueKind.Array or JsonValueKind.Object; Try / catch
try
{
var notes = JsonSerializer.Deserialize<ReleaseNoteInfo[]>(json, ElectronJson.Options);
}
catch (JsonException ex)
{
logger.LogWarning(ex, "Malformed releaseNotes payload: {Raw}", rawJson);
} Prevention
- Keep ElectronNET.API and ElectronNET.Host versions in sync
- Log raw payloads when deserialization fails
- Never send releaseNotes as a plain string
When it happens
Trigger: Deserializing a releaseNotes payload whose token is neither Null, StartArray, nor a recognized object start — e.g. a string value ('releaseNotes': 'Fixed bugs') instead of an object/array, or a number/boolean where an object was expected.
Common situations: Electron host/bridge version mismatch where the host sends releaseNotes as a plain string; custom IPC payloads passing through the same converter; manually crafted JSON in tests.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Invalid value for TitleBarOverlay. Expected boolean or an…
- Expected array for ModifierType list
- Expected string enum value
- Invalid value for PageSize. Expected string or an object.
- Unsupported token
AI-assisted analysis of ElectronNET/Electron.NET@87cc6f98b6 (2026-09-14).
Data as JSON: /api/errors/5126c5b1128293d6.
Report an issue: GitHub.
Appendix: source
Thrown at src/ElectronNET.API/Converter/ReleaseNotesConverter.cs:59
{
// Array of strings: ["Note A", "Note B"]
list.Add(new ReleaseNoteInfo { Note = reader.GetString() });
}
else if (reader.TokenType == JsonTokenType.StartObject)
{
// Array of objects: [{ "version": "1.0", "note": "..." }]
var entry = JsonSerializer.Deserialize<ReleaseNoteInfo>(ref reader, options) ?? new ReleaseNoteInfo();
list.Add(entry);
}
else
{
reader.Skip();
}
}
return list.ToArray();
default:
throw new JsonException($"Unexpected token {reader.TokenType} when reading releaseNotes.");
}
}
public override void Write(Utf8JsonWriter writer, ReleaseNoteInfo[] value, JsonSerializerOptions options)
{
if (value is null)
{
writer.WriteNullValue();
return;
}
if (value.Length == 0)
{
writer.WriteStartArray();
writer.WriteEndArray();
return;
}
View on GitHub (pinned to 87cc6f98b6)