{"record":{"id":"2c6e7c7b1dd821e2","repo":"tui-cs/Terminal.Gui","slug":"selectedcolor-must-be-between-0-and-15","errorCode":null,"errorMessage":"SelectedColor must be between 0 and 15.","messagePattern":"SelectedColor must be between 0 and 15\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Views/Color/ColorPicker.16.cs","lineNumber":239,"sourceCode":"            var oldValue = (ColorName16)_selectColorIndex;\n\n            ValueChangingEventArgs<ColorName16> changingArgs = new (oldValue, value);\n\n            if (OnValueChanging (changingArgs) || changingArgs.Handled)\n            {\n                return;\n            }\n\n            ValueChanging?.Invoke (this, changingArgs);\n\n            if (changingArgs.Handled)\n            {\n                return;\n            }\n\n            if (value is < 0 or > (ColorName16)15)\n            {\n                throw new ArgumentOutOfRangeException (nameof (value), @\"SelectedColor must be between 0 and 15.\");\n            }\n\n            _selectColorIndex = (int)value;\n            SetNeedsDraw ();\n\n            ValueChangedEventArgs<ColorName16> changedArgs = new (oldValue, value);\n            OnValueChanged (changedArgs);\n            ValueChanged?.Invoke (this, changedArgs);\n\n            ValueChangedUntyped?.Invoke (this, new ValueChangedEventArgs<object?> (oldValue, value));\n        }\n    }\n\n    /// <inheritdoc/>\n    public ColorName16 Value { get => SelectedColor; set => SelectedColor = value; }\n\n    /// <inheritdoc/>\n    object IValue.GetValue () => SelectedColor;","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Views/Color/ColorPicker.16.cs#L221-L257","documentation":"ColorPicker16 operates on the 16-color ANSI palette (ColorName16 enum, values 0–15). Setting SelectedColor to a value outside 0–15 is rejected because there is no corresponding palette slot. The check fires after the ValueChanging CWP event, so handlers can still intercept and cancel.","triggerScenarios":"Assigning picker.SelectedColor = (ColorName16)20 or any cast from an int outside 0–15; deserializing a color index from config without bounds checking.","commonSituations":"Casting a 256-color or true-color index into ColorName16; off-by-one from a color array; config/themes with stale values.","solutions":["Ensure the value is within the ColorName16 enum range (cast-checked or enum member).","Use the ColorName16 enum members directly instead of casting raw ints.","Validate config-sourced color values against 0–15 before assignment."],"exampleFix":"// before\npicker.SelectedColor = (ColorName16)idx;\n// after\npicker.SelectedColor = (ColorName16)Math.Clamp(idx, 0, 15);","handlingStrategy":"validation","validationCode":"view.SelectedColor = (ColorName16)Math.Clamp((int)raw, 0, 15);","typeGuard":"static bool IsValidColor16 (ColorName16 c) => (int)c is >= 0 and <= 15;","tryCatchPattern":null,"preventionTips":["Use ColorName16 enum members directly.","Clamp config-sourced ints to 0–15.","Do not cast 256/true-color indices into ColorName16."],"tags":["color","colorpicker","validation","enum"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}