{"record":{"id":"195ef76332beee38","repo":"tui-cs/Terminal.Gui","slug":"value-must-be-one-of-the-following-string-join","errorCode":null,"errorMessage":"Value must be one of the following: {string.Join (\", \", Values)}","messagePattern":"Value must be one of the following: (.+?)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Views/Selectors/SelectorBase.cs","lineNumber":234,"sourceCode":"            { Source: { } weakSource } when weakSource.TryGetTarget (out View? src) && src == this => true,\n            MouseBinding mouseBinding when mouseBinding.MouseEvent!.Flags.FastHasFlags (MouseFlags.LeftButtonDoubleClicked) => !DoubleClickAccepts,\n            KeyBinding { Key: { } } keyBinding when keyBinding.Key == Key.Enter => false,\n            null => false,\n            _ => true\n        };\n    }\n\n    /// <summary>\n    ///     Gets or sets the value of the selector. Will be <see langword=\"null\"/> if no value is set.\n    /// </summary>\n    public virtual int? Value\n    {\n        get;\n        set\n        {\n            if (value is { } && Values is { } && !Values.Contains ((int)value))\n            {\n                throw new ArgumentOutOfRangeException (nameof (value), @$\"Value must be one of the following: {string.Join (\", \", Values)}\");\n            }\n\n            if (field == value)\n            {\n                return;\n            }\n\n            int? previousValue = field;\n\n            // Raise IValue<int?>.ValueChanging (cancellable)\n            if (RaiseValueChanging (previousValue, value))\n            {\n                return;\n            }\n\n            Trace.Command (this, \"Value\", $\"{previousValue}->{value}\");\n            field = value;\n","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Views/Selectors/SelectorBase.cs#L216-L252","documentation":"Thrown by SelectorBase.Value setter when a non-null value is supplied but the Values collection is non-null and does not contain value. The selector's allowed values are explicitly enumerated in Values, so any selection must come from that set. The check runs before the equality short-circuit and before IValue.ValueChanging is raised. (Note the message string is interpolated at runtime, so the exact text includes the joined values.)","triggerScenarios":"Setting Value to an int not present in Values; assigning a value captured before Values was populated or after Values changed; enum-to-int conversion that yields a value outside the configured set; stale binding pushing an old selection.","commonSituations":"Rebinding the selector with a smaller Values set while a previous Value persists; converting an enum to int where the int isn't in the list; default(int)=0 assigned when 0 is not among Values.","solutions":["Verify membership before assigning: if (selector.Values is null || selector.Values.Contains(v)) selector.Value = v;","After changing Values, clear or re-clamp Value to a member of the new set.","For enums, prefer OptionSelectorTEnum which derives Values from the enum so membership is guaranteed."],"exampleFix":"// before\nselector.Value = candidate; // candidate not in Values -> throws 172\n\n// after\nif (selector.Values is null || selector.Values.Contains(candidate))\n{\n    selector.Value = candidate;\n}","handlingStrategy":"validation","validationCode":"if (selector.Values is null || selector.Values.Contains(candidate))\n{\n    selector.Value = candidate;\n}","typeGuard":"static bool ValueIsAllowed(SelectorBase s, int v) => s.Values is null || s.Values.Contains(v);","tryCatchPattern":null,"preventionTips":["Clear or re-clamp Value whenever Values changes.","Prefer OptionSelectorTEnum so Values derives from the enum automatically.","Guard default(int)=0 assignments when 0 is not among Values."],"tags":["selectorbase","validation","binding","precondition"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}