tui-cs/Terminal.Gui · error · ArgumentNullException
value
Error message
value
What it means
Thrown by the LinearRangeViewBase.Options setter (message is just the param name 'value' via nameof) when assigning null to the Options list. Although the getter returns an empty list as a fallback, the setter explicitly refuses null to keep the internal _options non-null invariant. The selected indices are then pruned against the new options.
Source
Thrown at Terminal.Gui/Views/LinearRange/LinearRangeViewBase.cs:368
protected virtual bool OnLegendsOrientationChanging (ValueChangingEventArgs<Orientation> args) => false;
/// <summary>Called after <see cref="LegendsOrientation"/> has changed.</summary>
protected virtual void OnLegendsOrientationChanged (ValueChangedEventArgs<Orientation> args) { }
/// <summary>LinearRange styles. <see cref="LinearRangeStyle"></see></summary>
public LinearRangeStyle Style { get; set; } = new ();
/// <summary>
/// Set the linear range options. When the new options no longer contain the previously selected
/// value(s), the selection is dropped (event semantics depend on the concrete subclass).
/// </summary>
public List<LinearRangeOption<TOption>> Options
{
get => _options ?? [];
set
{
// _options should never be null
_options = value ?? throw new ArgumentNullException (nameof (value));
// Drop any selected indices that are no longer valid
_setOptions.RemoveAll (i => i < 0 || i >= _options.Count);
if (_options.Count == 0)
{
return;
}
SetContentSize ();
}
}
/// <summary>
/// Internal accessor for whether a range is allowed to collapse to a single option (only meaningful
/// when <see cref="RenderMode"/> is <see cref="LinearRangeRenderMode.Span"/>). Exposed publicly only
/// by <see cref="LinearRange{T}"/>.
/// </summary>View on GitHub (pinned to 2e47b11478)
Solutions
- Assign an empty list instead of null: rangeView.Options = options ?? [];
- Ensure the source collection is initialised to a non-null list in its owner before binding.
- Initialise the bound property with a default: public List<LinearRangeOption<T>> Options { get; set; } = [];
Example fix
// before
range.Options = maybeOptions; // null when nothing selected
// after
range.Options = maybeOptions ?? [];
// or at the source:
public List<LinearRangeOption<T>> Options { get; set; } = []; Defensive patterns
Strategy: validation
Validate before calling
range.Options = maybeOptions ?? [];
Type guard
static bool HasValidOptions<T>(List<LinearRangeOption<T>>? o) => o is not null;
Prevention
- Always assign [] instead of null.
- Initialise bound collection properties to [] at declaration.
- Coerce deserialised null collections to empty before binding.
When it happens
Trigger: Assigning rangeView.Options = null; or passing a variable that is null (e.g. a list built conditionally that stayed null, or a deserialised collection whose source was absent).
Common situations: MVVM/binding where the model collection is initially null; JSON deserialisation with missing-options defaulting to null; refactor that replaced a field initialiser with a nullable property.
Related errors
- The source stream must be seekable (CanSeek property)
- Zoom level must be a finite number.
- Maximum sixel palette colors must be greater than zero.
- value
- SelectedItem must be greater than 0 or less than the number
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/dbd39b753e9ee547.
Report an issue: GitHub.