ElectronNET/Electron.NET · error · JsonException
Expected array for ModifierType list
Error message
Expected array for ModifierType list
What it means
ModifierTypeListConverter.Read is a System.Text.Json converter for List<ModifierType>. It requires the incoming JSON token to be a StartArray; anything else (number, string, object, null-token shapes) cannot be mapped to a modifier list and is rejected with a JsonException "Expected array for ModifierType list". It exists because ModifierType values arrive from Electron as a JSON array of strings.
Solutions
- Send the value as a JSON array of strings: "modifiers": ["ctrl", "shift"].
- Fix the JS/Electron side to pass an array (wrap single values: [modifier]).
- Update the .NET model/converter if the upstream schema intentionally changed to a single-value shape.
- Validate/normalize the payload before deserialization (if Array.isArray check on the JS side).
Example fix
// before
{ "modifiers": "ctrl" }
// after
{ "modifiers": ["ctrl"] } Defensive patterns
Strategy: type-guard
Validate before calling
if (payload.modifiers != null && !Array.isArray(payload.modifiers))
payload.modifiers = [payload.modifiers]; // normalize before sending over IPC Type guard
function isModifierTypeList(v: unknown): v is string[] {
return Array.isArray(v) && v.every(x => typeof x === 'string');
} Try / catch
try
{
var list = JsonSerializer.Deserialize<List<ModifierType>>(json, ElectronJson.Options);
}
catch (JsonException ex) when (ex.Message.Contains("Expected array for ModifierType list"))
{
Logger.Error("'modifiers' must be a JSON array of strings, e.g. [\"ctrl\"].");
} Prevention
- On the JS side, always pass arrays (wrap single values in []).
- Type the payload in TypeScript (ModifierType[]) so mistakes surface at compile time.
- Keep Electron front-end and .NET model versions in lockstep.
- Add IPC payload schema tests around modifier arguments.
When it happens
Trigger: Deserializing JSON where a ModifierType list property holds a non-array value — e.g. "modifiers": "ctrl" (string) or "modifiers": 3 (number) or an object — while ElectronJson.Options applies ModifierTypeListConverter to that property.
Common situations: Electron/IPC payload schema changed or was hand-crafted with a single modifier instead of an array; JS side sent a comma-joined string; tests/fixtures using the wrong JSON shape; version mismatch between the Electron front-end payload and the .NET model.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- Expected string enum value
- Invalid value for PageSize. Expected string or an object.
- Unsupported token
- Unexpected token when reading releaseNotes.
- Invalid value for TitleBarOverlay. Expected boolean or an…
AI-assisted analysis of ElectronNET/Electron.NET@87cc6f98b6 (2026-09-14).
Data as JSON: /api/errors/7b634a8fd998ab17.
Report an issue: GitHub.
Appendix: source
Thrown at src/ElectronNET.API/Converter/ModifierTypeListConverter.cs:24
using System.Text.Json;
using System.Text.Json.Serialization;
/// <summary>
///
/// </summary>
public class ModifierTypeListConverter : JsonConverter<List<ModifierType>>
{
public override List<ModifierType> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Null)
{
return null;
}
var list = new List<ModifierType>();
if (reader.TokenType != JsonTokenType.StartArray)
{
throw new JsonException("Expected array for ModifierType list");
}
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndArray) break;
if (reader.TokenType != JsonTokenType.String) throw new JsonException("Expected string enum value");
var s = reader.GetString();
list.Add((ModifierType)Enum.Parse(typeof(ModifierType), s, ignoreCase: true));
}
return list;
}
public override void Write(Utf8JsonWriter writer, List<ModifierType> value, JsonSerializerOptions options)
{
writer.WriteStartArray();
foreach (var modifier in value)
{View on GitHub (pinned to 87cc6f98b6)