spectreconsole/spectre.console · error · ArgumentNullException

Value cannot be null. (Parameter 'text')

Error message

Value cannot be null. (Parameter 'text')

What it means

The TableTitle constructor requires non-null text and throws ArgumentNullException on 'text' via Text = text ?? throw. TableTitle backs table Title and Caption; a null string is rejected so downstream markup rendering never sees null.

Source

Thrown at src/Spectre.Console/Widgets/Table/TableTitle.cs:25

{
    /// <summary>
    /// Gets the title text.
    /// </summary>
    public string Text { get; }

    /// <summary>
    /// Gets or sets the title style.
    /// </summary>
    public Style? Style { get; set; }

    /// <summary>
    /// Initializes a new instance of the <see cref="TableTitle"/> class.
    /// </summary>
    /// <param name="text">The title text.</param>
    /// <param name="style">The title style.</param>
    public TableTitle(string text, Style? style = null)
    {
        Text = text ?? throw new ArgumentNullException(nameof(text));
        Style = style;
    }

    /// <summary>
    /// Sets the title style.
    /// </summary>
    /// <param name="style">The title style.</param>
    /// <returns>The same instance so that multiple calls can be chained.</returns>
    public TableTitle SetStyle(Style? style)
    {
        Style = style ?? Spectre.Console.Style.Plain;
        return this;
    }

    /// <summary>
    /// Sets the title style.
    /// </summary>
    /// <param name="style">The title style.</param>

View on GitHub (pinned to 0acc92fada)

Solutions

  1. Null-coalesce: new TableTitle(text ?? string.Empty, style).
  2. Skip setting the title/caption when the source is null instead of constructing TableTitle.
  3. Validate the title source at the boundary before building the title object.

Example fix

// before
table.Title = new TableTitle(maybeNullTitle);

// after
if (maybeNullTitle is not null)
    table.Title = new TableTitle(maybeNullTitle);
Defensive patterns

Strategy: validation

Validate before calling

if (text is null) return; // skip title
table.Title = new TableTitle(text, style);

Prevention

When it happens

Trigger: new TableTitle(null); passing a nullable string that is null; assigning a title/caption from a source that can be null without coalescing.

Common situations: Optional title from config/data that is absent (null); a localized string resource resolving to null; reusing a title variable that was conditionally set.

Related errors


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