spectreconsole/spectre.console · error · ArgumentNullException

Value cannot be null. (Parameter 'header')

Error message

Value cannot be null. (Parameter 'header')

What it means

The TableColumn(IRenderable header) constructor requires a non-null header and throws ArgumentNullException on 'header'. The string overload wraps input in new Markup(header).Overflow(Ellipsis) then delegates to this constructor, so a null IRenderable passed directly is the trigger.

Source

Thrown at src/Spectre.Console/Widgets/Table/TableColumn.cs:83

    /// </summary>
    public Justify? Alignment { get; set; }

    /// <summary>
    /// Initializes a new instance of the <see cref="TableColumn"/> class.
    /// </summary>
    /// <param name="header">The table column header.</param>
    public TableColumn(string header)
        : this(new Markup(header).Overflow(Overflow.Ellipsis))
    {
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="TableColumn"/> class.
    /// </summary>
    /// <param name="header">The <see cref="IRenderable"/> instance to use as the table column header.</param>
    public TableColumn(IRenderable header)
    {
        Header = header ?? throw new ArgumentNullException(nameof(header));
        Width = null;
        Padding = new Padding(1, 0, 1, 0);
        NoWrap = false;
        Alignment = null;
    }
}

/// <summary>
/// Contains extension methods for <see cref="TableColumn"/>.
/// </summary>
public static class TableColumnExtensions
{
    /// <summary>
    /// Sets the table column header.
    /// </summary>
    /// <param name="column">The table column.</param>
    /// <param name="header">The table column header markup text.</param>
    /// <returns>The same instance so that multiple calls can be chained.</returns>

View on GitHub (pinned to 0acc92fada)

Solutions

  1. Pass a guaranteed non-null renderable: new TableColumn(header ?? new Markup(string.Empty)).
  2. Prefer the string overload new TableColumn("text") which never yields a null IRenderable.
  3. Validate the header source before constructing columns.

Example fix

// before
var col = new TableColumn(maybeNullRenderable);

// after
var col = new TableColumn(maybeNullRenderable ?? new Markup(string.Empty));
Defensive patterns

Strategy: validation

Validate before calling

ArgumentNullException.ThrowIfNull(header);
var col = new TableColumn(header ?? new Markup(string.Empty));

Prevention

When it happens

Trigger: new TableColumn((IRenderable)null); passing a nullable IRenderable that is null; a header factory returning null.

Common situations: Constructing columns in a loop from data where some entries produce null renderables; building columns before the header source is populated; deserialized/config-driven headers that can be absent.

Related errors


AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13). Data as JSON: /api/errors/423421b2ffa56a22. Report an issue: GitHub.