{"record":{"id":"0625292d3e1f7cef","repo":"tui-cs/Terminal.Gui","slug":"checkbox-value-not-found","errorCode":null,"errorMessage":"CheckBox value not found","messagePattern":"CheckBox value not found","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Views/Selectors/SelectorBase.cs","lineNumber":485,"sourceCode":"        _checkBoxValues [checkbox] = value;\n\n        return checkbox;\n    }\n\n    /// <summary>\n    ///     Gets the int value associated with a checkbox. For testing and advanced scenarios.\n    /// </summary>\n    /// <param name=\"checkbox\">The checkbox to get the value for</param>\n    /// <returns>The integer value associated with the checkbox</returns>\n    /// <exception cref=\"InvalidOperationException\">If the checkbox is not found or not part of this selector</exception>\n    public int GetCheckBoxValue (CheckBox checkbox)\n    {\n        if (_checkBoxValues.TryGetValue (checkbox, out int value))\n        {\n            return value;\n        }\n\n        throw new InvalidOperationException (\"CheckBox value not found\");\n    }\n\n    private int _horizontalSpace = 2;\n\n    /// <summary>\n    ///     Gets or sets the horizontal space for this <see cref=\"OptionSelector\"/> if the <see cref=\"Orientation\"/> is\n    ///     <see cref=\"Orientation.Horizontal\"/>\n    /// </summary>\n    public int HorizontalSpace\n    {\n        get => _horizontalSpace;\n        set\n        {\n            if (_horizontalSpace == value)\n            {\n                return;\n            }\n            _horizontalSpace = value;","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Views/Selectors/SelectorBase.cs#L467-L503","documentation":"Thrown by SelectorBase.GetCheckBoxValue when the passed CheckBox is not a key in the internal _checkBoxValues map — i.e. the checkbox does not belong to this selector. The map is the source of truth for the integer each checkbox represents, so a foreign checkbox has no value to return. Intended for testing/advanced scenarios per its doc comment.","triggerScenarios":"Passing a CheckBox from a different selector, a manually new'd CheckBox, or a checkbox obtained before the selector built its internal map. Also calling it after the selector was rebuilt/rebound so old checkbox references are stale.","commonSituations":"Unit tests passing an arbitrary CheckBox; holding checkbox references across a rebuild of the selector's options; mixing checkboxes from two selectors in shared handler code.","solutions":["Only pass checkboxes obtained from this selector's own SubViews and only while its options are unchanged.","Before calling, check membership via the selector's own subviews: if (selector.SubViews.OfType<CheckBox>().Contains(cb)) ...","Re-acquire checkbox references whenever Options/Values are rebuilt."],"exampleFix":"// before\nint v = selector.GetCheckBoxValue(maybeForeignCheckbox); // throws 173\n\n// after\nif (selector.SubViews.OfType<CheckBox>().Contains(maybeForeignCheckbox))\n{\n    int v = selector.GetCheckBoxValue(maybeForeignCheckbox);\n}","handlingStrategy":"type-guard","validationCode":"if (selector.SubViews.OfType<CheckBox>().Contains(cb))\n{\n    int v = selector.GetCheckBoxValue(cb);\n}","typeGuard":"static bool CheckBoxBelongsTo(SelectorBase s, CheckBox cb) =>\n    s.SubViews.OfType<CheckBox>().Contains(cb);","tryCatchPattern":null,"preventionTips":["Only pass checkboxes obtained from the same selector.","Re-acquire checkbox references after rebuilding options.","Avoid new'ing standalone CheckBoxes to pass to this API."],"tags":["selectorbase","checkbox","validation","precondition"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}