spectreconsole/spectre.console · error · ArgumentNullException
Value cannot be null. (Parameter 'value')
Error message
Value cannot be null. (Parameter 'value')
What it means
The TableColumn.Header setter requires a non-null IRenderable. The setter null-coalesces with 'throw new ArgumentNullException(nameof(value))', so assigning null throws immediately. This guards downstream rendering from null-dereference when laying out the header.
Source
Thrown at src/Spectre.Console/Widgets/Table/TableColumn.cs:24
public sealed class TableColumn : IColumn
{
private IRenderable _header = null!;
private IRenderable? _footer;
/// <summary>
/// Gets or sets the column header.
/// </summary>
public IRenderable Header
{
get => _header;
set
{
if (value is TableCell cell && cell.ColumnSpan > 1)
{
throw new InvalidOperationException("Column spanning is not supported in table header rows.");
}
_header = value ?? throw new ArgumentNullException(nameof(value));
}
}
/// <summary>
/// Gets or sets the column footer.
/// </summary>
public IRenderable? Footer
{
get => _footer;
set
{
if (value is TableCell cell && cell.ColumnSpan > 1)
{
throw new InvalidOperationException("Column spanning is not supported in table footer rows.");
}
_footer = value;
}View on GitHub (pinned to 0acc92fada)
Solutions
- Null-coalesce before assignment: column.Header = maybeNull ?? new Markup(string.Empty).
- Validate with ArgumentNullException.ThrowIfNull(value) at the caller boundary.
- Use Markup.Empty or new Markup(string.Empty) as a sentinel instead of null.
Example fix
// before column.Header = headerRenderable; // headerRenderable may be null // after column.Header = headerRenderable ?? new Markup(string.Empty);
Defensive patterns
Strategy: validation
Validate before calling
ArgumentNullException.ThrowIfNull(value); column.Header = value ?? new Markup(string.Empty);
Prevention
- Coalesce nullable header sources with ?? new Markup(string.Empty).
- Use the string TableColumn overload to avoid null IRenderable entirely.
- Run nullable reference analysis with <Nullable>enable</Nullable> to catch nulls at compile time.
When it happens
Trigger: column.Header = null; new TableColumn((IRenderable)null); or assigning a nullable IRenderable variable (IRenderable?) that happens to be null.
Common situations: A factory/builder returning null for an absent header; a nullable reference passed without a null check; clearing a header by assigning null instead of an empty Markup; deserialized data yielding null rendered as header.
Related errors
- Value cannot be null. (Parameter 'header')
- Value cannot be null. (Parameter 'text')
- Column spanning is not supported in table header rows.
- Column spanning is not supported in table {rowType} rows.
- Table row index cannot be negative.
AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13).
Data as JSON: /api/errors/9f52ed6cfda76939.
Report an issue: GitHub.