{"record":{"id":"9cc14fa42a74c93b","repo":"tui-cs/Terminal.Gui","slug":"propertyname-error-parsing-key-value-ioe-mess","errorCode":null,"errorMessage":"{propertyName}: Error parsing Key value: {ioe.Message}","messagePattern":"(.+?): Error parsing Key value: (.+?)","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Configuration/KeyCodeJsonConverter.cs","lineNumber":68,"sourceCode":"                                    break;\n                                }\n\n                                if (key == KeyCode.Null)\n                                {\n                                    throw new JsonException (\n                                                             $\"{propertyName}: \\\"{reader.GetString ()}\\\" is not a valid Key.\"\n                                                            );\n                                }\n                            }\n                            else if (reader.TokenType == JsonTokenType.Number)\n                            {\n                                try\n                                {\n                                    key = (KeyCode)reader.GetInt32 ();\n                                }\n                                catch (InvalidOperationException ioe)\n                                {\n                                    throw new JsonException ($\"{propertyName}: Error parsing Key value: {ioe.Message}\", ioe);\n                                }\n                                catch (FormatException ioe)\n                                {\n                                    throw new JsonException ($\"{propertyName}: Error parsing Key value: {ioe.Message}\", ioe);\n                                }\n                            }\n\n                            break;\n\n                        case \"modifiers\":\n                            if (reader.TokenType == JsonTokenType.StartArray)\n                            {\n                                while (reader.Read ())\n                                {\n                                    if (reader.TokenType == JsonTokenType.EndArray)\n                                    {\n                                        break;\n                                    }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Configuration/KeyCodeJsonConverter.cs#L50-L86","documentation":"Thrown by KeyCodeJsonConverter.Read (KeyCodeJsonConverter.cs:66-69) when the \"Key\" property value is a JSON number but reader.GetInt32() throws InvalidOperationException. GetInt32 throws InvalidOperationException when the token, while nominally a Number, cannot be read as an int in the current reader state (e.g. the value is a JSON number encoded as a string token, or the reader is positioned on a property name rather than a value). The inner exception message is surfaced.","triggerScenarios":"The \"Key\" property is a number but the Utf8JsonReader cannot yield an Int32 — most commonly because reader.Read() was not advanced onto the value token, or the number is presented as a quoted string \"65\". The catch wraps it as a JsonException with the propertyName.","commonSituations":"Config JSON has \"Key\": \"65\" (string-quoted number) instead of \"Key\": 65. A malformed JSON stream where the reader state is inconsistent. Tooling that quotes all values.","solutions":["If you intend a numeric KeyCode, write it as a bare JSON number: \"Key\": 65 (no quotes).","Prefer the KeyCode enum name string form (\"Key\": \"Enter\") over numeric codes for readability and stability across enum renumbering.","Ensure no extra reader advancement issues by validating the JSON object is well-formed with a standard parser first.","Use the Key[] string-array format for keybindings, which avoids the numeric path entirely."],"exampleFix":"// before (quoted number causes reader state issue)\n{ \"Key\": \"65\" }\n\n// after (bare number, or better, the enum name)\n{ \"Key\": 65 }\n// or\n{ \"Key\": \"A\" }","handlingStrategy":"validation","validationCode":"using System.Text.Json;\n\nstatic bool KeyNumberIsBareInt (string json, string propertyName)\n{\n    using JsonDocument doc = JsonDocument.Parse (json);\n    // Walk to the property of interest; this is illustrative.\n    return true; // ensure \"Key\": 65 not \"Key\": \"65\"\n}\n\n// Prefer: validate the \"Key\" number token is an unquoted integer in the raw JSON.","typeGuard":"static bool IsBareJsonNumber (JsonElement el) => el.ValueKind == JsonValueKind.Number;","tryCatchPattern":"try\n{\n    ConfigurationManager.Load (configJson);\n}\ncatch (JsonException ex) when (ex.Message.Contains (\"Error parsing Key value\"))\n{\n    // The \"Key\" number could not be read as Int32. Unquote it / convert to enum name.\n}","preventionTips":["Write numeric Key values as bare JSON integers (no quotes): \"Key\": 65.","Prefer the KeyCode enum name string form for readability and stability.","Avoid quoting numeric values in config.","Use the Key[] string-array format to sidestep the numeric path entirely."],"tags":["json","configuration","keybindings","key","serialization"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}