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 Panel(IRenderable) constructor when the content argument is null. A Panel requires a child renderable to draw inside its border. Note the string overload delegates to new Markup(text) which itself handles null text.
Source
Thrown at src/Spectre.Console/Widgets/Panel.cs:68
/// </summary>
internal bool Inline { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="Panel"/> class.
/// </summary>
/// <param name="text">The panel content.</param>
public Panel(string text)
: this(new Markup(text))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Panel"/> class.
/// </summary>
/// <param name="content">The panel content.</param>
public Panel(IRenderable content)
{
_child = content ?? throw new ArgumentNullException(nameof(content));
}
/// <inheritdoc/>
protected override Measurement Measure(RenderOptions options, int maxWidth)
{
var child = new Padder(_child, Padding);
return Measure(options, maxWidth, child);
}
private Measurement Measure(RenderOptions options, int maxWidth, IRenderable child)
{
var edgeWidth = (options.GetSafeBorder(this) is not NoBoxBorder) ? EdgeWidth : 0;
var childWidth = child.Measure(options, maxWidth - edgeWidth);
if (Width != null)
{
var width = Width.Value - edgeWidth;
View on GitHub (pinned to 0acc92fada)
Solutions
- Pass a non-null IRenderable such as new Text("...") or new Markup("...").
- Use the string overload 'new Panel(text)' which tolerates null via Markup.
- Null-check before constructing the Panel.
Example fix
// before var panel = new Panel(maybeNullRenderable); // after var panel = new Panel(maybeNullRenderable ?? new Text(string.Empty));
Defensive patterns
Strategy: type-guard
Validate before calling
if (content is null) throw new ArgumentNullException(nameof(content)); var panel = new Panel(content);
Type guard
static bool HasValidPanelContent(IRenderable? content) => content is not null;
Prevention
- Prefer the string overload new Panel(text) when content is a string.
- Coalesce null renderables with a default before construction.
When it happens
Trigger: Constructing 'new Panel((IRenderable)null)' or passing a variable of type IRenderable that is null.
Common situations: Passing a renderable obtained from a method that returned null, or an optional content variable that was not set.
Related errors
- Value cannot be null. (Parameter 'text')
- Value cannot be null. (Parameter 'children')
- 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/6988dfb6ac1b6529.
Report an issue: GitHub.