tui-cs/Terminal.Gui · error · ArgumentNullException

Y cannot be null

Error message

Y cannot be null

What it means

The Y property (vertical position) must be a non-null Pos. The layout engine cannot resolve a null vertical position — the default is Pos.Absolute(0), and null is treated as a programmer error.

Source

Thrown at Terminal.Gui/ViewBase/View.Layout.cs:339

    ///         resulting in the
    ///         view being laid out and redrawn as appropriate in the next iteration.
    ///     </para>
    ///     <para>
    ///         Changing this property will cause <see cref="Frame"/> to be updated.
    ///     </para>
    ///     <para>The default value is <c>Pos.Absolute (0)</c>.</para>
    /// </remarks>
    public Pos Y
    {
        get => _y;
        set
        {
            if (Equals (_y, value))
            {
                return;
            }

            _y = value ?? throw new ArgumentNullException (nameof (value), @$"{nameof (Y)} cannot be null");
            PosDimSet ();

            NeedsClearScreenNextIteration ();
        }
    }

    private Dim _height = Dim.Absolute (0);

    /// <summary>
    ///     Gets or sets the declarative height for the view.
    /// </summary>
    /// <value>The <see cref="Dim"/> object representing the height of the view (the number of rows).</value>
    /// <remarks>
    ///     <para>
    ///         See the View Layout Deep Dive for more information:
    ///         <see href="https://tui-cs.github.io/Terminal.Gui/docs/layout.html"/>
    ///     </para>
    ///     <para>

View on GitHub (pinned to 2e47b11478)

Solutions

  1. Use Pos.Absolute(n), Pos.Center(), Pos.Percent(n), or Pos.Top(otherView).
  2. Default to Pos.Absolute(0) instead of null when clearing.

Example fix

// before
view.Y = computedPos;
// after
view.Y = computedPos ?? Pos.Absolute(0);
Defensive patterns

Strategy: validation

Validate before calling

view.Y = pos ?? Pos.Absolute(0);

Type guard

static bool IsValidPos (Pos? p) => p is not null;

Prevention

When it happens

Trigger: Assigning view.Y = null; or a Pos variable holding null because a computation or lookup returned nothing.

Common situations: Helper returning null Pos for an edge case, conditional setup that skips Y assignment, nullable field used before initialization.

Related errors


AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13). Data as JSON: /api/errors/977005842a0d6d16. Report an issue: GitHub.