spectreconsole/spectre.console · error · ArgumentNullException
Value cannot be null. (Parameter 'children')
Error message
Value cannot be null. (Parameter 'children')
What it means
Thrown by the Rows(IEnumerable<IRenderable>) constructor when the children collection is null. The params overload delegates to this overload and passes the array; a null IEnumerable is rejected. An empty collection is allowed (renders nothing).
Source
Thrown at src/Spectre.Console/Widgets/Rows.cs:28
/// <inheritdoc/>
public bool Expand { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="Rows"/> class.
/// </summary>
/// <param name="items">The items to render as rows.</param>
public Rows(params IRenderable[] items)
: this((IEnumerable<IRenderable>)items)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Rows"/> class.
/// </summary>
/// <param name="children">The items to render as rows.</param>
public Rows(IEnumerable<IRenderable> children)
{
_children = new List<IRenderable>(children ?? throw new ArgumentNullException(nameof(children)));
}
/// <inheritdoc/>
protected override Measurement Measure(RenderOptions options, int maxWidth)
{
if (Expand)
{
return new Measurement(maxWidth, maxWidth);
}
else
{
var measurements = _children.Select(c => c.Measure(options, maxWidth)).ToArray();
if (measurements.Length > 0)
{
return new Measurement(
measurements.Max(c => c.Min),
measurements.Max(c => c.Max));
}View on GitHub (pinned to 0acc92fada)
Solutions
- Pass a non-null collection; use Enumerable.Empty<IRenderable>() for no rows.
- Coalesce with '?? Array.Empty<IRenderable>()'.
- Initialize the source collection before constructing Rows.
Example fix
// before var rows = new Rows(maybeNullList); // after var rows = new Rows(maybeNullList ?? Array.Empty<IRenderable>());
Defensive patterns
Strategy: type-guard
Validate before calling
children ??= Array.Empty<IRenderable>(); var rows = new Rows(children);
Type guard
static bool HasValidRowsCollection(IEnumerable<IRenderable>? children) => children is not null;
Prevention
- Coalesce potentially null collections with Array.Empty<IRenderable>().
- Initialize source lists before constructing Rows.
When it happens
Trigger: Constructing 'new Rows((IEnumerable<IRenderable>)null)' or passing a list variable that is null.
Common situations: A filter/LINQ query that can return null, or a field that was never initialized.
Related errors
- Value cannot be null. (Parameter 'content')
- Value cannot be null. (Parameter 'text')
- Value cannot be null. (Parameter 'title')
- Value cannot be null. (Parameter 'content')
- Must be > 1
AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13).
Data as JSON: /api/errors/793d1435b63049de.
Report an issue: GitHub.