{"record":{"id":"bab41e8e58498931","repo":"tui-cs/Terminal.Gui","slug":"invalid-color-name-kvp-key","errorCode":null,"errorMessage":"Invalid color name: {kvp.Key}","messagePattern":"Invalid color name: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Drawing/Color/Color.cs","lineNumber":205,"sourceCode":"    public static Dictionary<ColorName16, string> Colors16\n    {\n        get =>\n\n            // Transform _colorToNameMap into a Dictionary<ColorNames,string>\n            ColorExtensions.ColorToName16Map!.ToDictionary (static kvp => kvp.Value, static kvp => kvp.Key.ToString (\"g\"));\n        set\n        {\n            // Transform Dictionary<ColorNames,string> into _colorToNameMap\n            ColorExtensions.ColorToName16Map = value.ToFrozenDictionary (GetColorToNameMapKey, GetColorToNameMapValue);\n\n            return;\n\n            static Color GetColorToNameMapKey (KeyValuePair<ColorName16, string> kvp) => new (kvp.Value);\n\n            static ColorName16 GetColorToNameMapValue (KeyValuePair<ColorName16, string> kvp) =>\n                Enum.TryParse (kvp.Key.ToString (), true, out ColorName16 colorName)\n                    ? colorName\n                    : throw new ArgumentException ($\"Invalid color name: {kvp.Key}\");\n        }\n    }\n\n    /// <summary>\n    ///     Gets the <see cref=\"Color\"/> using a legacy 16-color <see cref=\"ColorName16\"/> value. <see langword=\"get\"/> will\n    ///     return the closest 16 color match to the true color when no exact value is found.\n    /// </summary>\n    /// <remarks>\n    ///     Get returns the <see cref=\"GetClosestNamedColor16(Color)\"/> of the closest 24-bit color value. Set sets the RGB\n    ///     value using a hard-coded map.\n    /// </remarks>\n    public AnsiColorCode GetAnsiColorCode () => ColorExtensions.ColorName16ToAnsiColorMap [GetClosestNamedColor16 ()];\n\n    /// <summary>\n    ///     Gets the <see cref=\"Color\"/> using a legacy 16-color <see cref=\"ColorName16\"/> value. <see langword=\"get\"/>\n    ///     will return the closest 16 color match to the true color when no exact value is found.\n    /// </summary>\n    /// <remarks>","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drawing/Color/Color.cs#L187-L223","documentation":"Thrown by the setter of ColorExtensions.ColorToName16Map when a Dictionary<ColorName16,string> entry's key cannot be parsed back into a ColorName16 enum value via Enum.TryParse. It is an ArgumentException naming the offending kvp.Key. This is a configuration-validation error in the 16-color name mapping, not a runtime color parse error.","triggerScenarios":"Assigning ColorExtensions.ColorToName16Map with a dictionary whose keys include undefined ColorName16 enum values (e.g. a cast like (ColorName16)999) or keys whose ToString() is not a valid enum name.","commonSituations":"Custom theme/configuration files that supply a color-name-to-string mapping with an invalid or outdated ColorName16 identifier, or programmatically building the dictionary with invalid enum casts.","solutions":["Ensure every dictionary key is a defined ColorName16 enum value (Enum.IsDefined check).","Validate keys against Enum.GetNames<ColorName16>() before assigning the map.","Correct or remove the offending entry reported in the message."],"exampleFix":"// before\nColorExtensions.ColorToName16Map = customMap;\n\n// after\nforeach (var k in customMap.Keys)\n    if (!Enum.IsDefined(k)) throw new InvalidOperationException($\"Bad ColorName16 key: {k}\");\nColorExtensions.ColorToName16Map = customMap;","handlingStrategy":"validation","validationCode":"foreach (var k in map.Keys)\n    if (!Enum.IsDefined(k)) throw new InvalidOperationException($\"Bad key {k}\");\nColorExtensions.ColorToName16Map = map;","typeGuard":"static bool IsValidColorName16Map(Dictionary<ColorName16,string> map) => map.Keys.All(Enum.IsDefined);","tryCatchPattern":"try { ColorExtensions.ColorToName16Map = map; } catch (ArgumentException ex) { /* ex.Message names bad key */ }","preventionTips":["Only use defined ColorName16 enum values as dictionary keys.","Validate custom theme maps with Enum.IsDefined before assignment.","Treat this as a config-build-time error, not a runtime one."],"tags":["color","configuration","enum","theme","argument-exception"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}