spectreconsole/spectre.console · error · ArgumentNullException
Value cannot be null. (Parameter 'content')
Error message
Value cannot be null. (Parameter 'content')
What it means
Thrown by the TableCell(IRenderable) constructor when the content argument is null. A cell must contain a renderable. The string overload coalesces null markup to string.Empty via new Markup(markup ?? string.Empty), so it tolerates null.
Source
Thrown at src/Spectre.Console/Widgets/Table/TableCell.cs:24
public sealed class TableCell : IRenderable
{
/// <summary>
/// Gets the cell content.
/// </summary>
public IRenderable Content { get; }
/// <summary>
/// Gets the number of columns this cell spans.
/// </summary>
public int ColumnSpan { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="TableCell"/> class.
/// </summary>
/// <param name="content">The cell content.</param>
public TableCell(IRenderable content)
{
Content = content ?? throw new ArgumentNullException(nameof(content));
ColumnSpan = 1;
}
/// <summary>
/// Initializes a new instance of the <see cref="TableCell"/> class.
/// </summary>
/// <param name="markup">Markup text.</param>
public TableCell(string markup)
: this(new Markup(markup ?? string.Empty))
{
}
/// <summary>
/// Sets the number of columns this cell should span.
/// </summary>
/// <param name="span">The number of columns to span.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public TableCell Span(int span)View on GitHub (pinned to 0acc92fada)
Solutions
- Pass a non-null IRenderable.
- Use the string overload 'new TableCell(markup)' which tolerates null.
- Coalesce with '?? new Markup(string.Empty)'.
Example fix
// before var cell = new TableCell(maybeNullRenderable); // after var cell = new TableCell(maybeNullRenderable ?? new Markup(string.Empty));
Defensive patterns
Strategy: type-guard
Validate before calling
if (content is null) throw new ArgumentNullException(nameof(content)); var cell = new TableCell(content);
Type guard
static bool HasValidCellContent(IRenderable? content) => content is not null;
Prevention
- Prefer the string overload new TableCell(markup) when content is a string.
- Coalesce null renderables with new Markup(string.Empty).
When it happens
Trigger: Constructing 'new TableCell((IRenderable)null)' or passing a null IRenderable variable.
Common situations: Content renderable obtained from a method that can return null, or a conditional expression that yields null.
Related errors
- Value cannot be null. (Parameter 'content')
- Value cannot be null. (Parameter 'text')
- Value cannot be null. (Parameter 'children')
- Value cannot be null. (Parameter 'title')
- Must be > 1
AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13).
Data as JSON: /api/errors/54cae398de874723.
Report an issue: GitHub.