{"record":{"id":"7b634a8fd998ab17","repo":"ElectronNET/Electron.NET","slug":"expected-array-for-modifiertype-list","errorCode":null,"errorMessage":"Expected array for ModifierType list","messagePattern":"Expected array for ModifierType list","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"src/ElectronNET.API/Converter/ModifierTypeListConverter.cs","lineNumber":24,"sourceCode":"using System.Text.Json;\nusing System.Text.Json.Serialization;\n\n/// <summary>\n/// \n/// </summary>\npublic class ModifierTypeListConverter : JsonConverter<List<ModifierType>>\n{\n    public override List<ModifierType> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)\n    {\n        if (reader.TokenType == JsonTokenType.Null)\n        {\n            return null;\n        }\n\n        var list = new List<ModifierType>();\n        if (reader.TokenType != JsonTokenType.StartArray)\n        {\n            throw new JsonException(\"Expected array for ModifierType list\");\n        }\n\n        while (reader.Read())\n        {\n            if (reader.TokenType == JsonTokenType.EndArray) break;\n            if (reader.TokenType != JsonTokenType.String) throw new JsonException(\"Expected string enum value\");\n            var s = reader.GetString();\n            list.Add((ModifierType)Enum.Parse(typeof(ModifierType), s, ignoreCase: true));\n        }\n\n        return list;\n    }\n\n    public override void Write(Utf8JsonWriter writer, List<ModifierType> value, JsonSerializerOptions options)\n    {\n        writer.WriteStartArray();\n        foreach (var modifier in value)\n        {","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/ElectronNET/Electron.NET/blob/87cc6f98b6a9c5968d7846c0e775ea713bd0d7b2/src/ElectronNET.API/Converter/ModifierTypeListConverter.cs#L6-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\n{ \"modifiers\": \"ctrl\" }\n// after\n{ \"modifiers\": [\"ctrl\"] }","handlingStrategy":"type-guard","validationCode":"if (payload.modifiers != null && !Array.isArray(payload.modifiers))\n    payload.modifiers = [payload.modifiers]; // normalize before sending over IPC","typeGuard":"function isModifierTypeList(v: unknown): v is string[] {\n  return Array.isArray(v) && v.every(x => typeof x === 'string');\n}","tryCatchPattern":"try\n{\n    var list = JsonSerializer.Deserialize<List<ModifierType>>(json, ElectronJson.Options);\n}\ncatch (JsonException ex) when (ex.Message.Contains(\"Expected array for ModifierType list\"))\n{\n    Logger.Error(\"'modifiers' must be a JSON array of strings, e.g. [\\\"ctrl\\\"].\");\n}","preventionTips":["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."],"tags":["json","deserialization","converter","type-mismatch"],"backgroundTag":"incompatible-source-type","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"}