spectreconsole/spectre.console · error · InvalidOperationException

Minimum size must be equal to or greater than 1

Error message

Minimum size must be equal to or greater than 1

What it means

Thrown by the Layout.MinimumSize setter when value is less than 1. MinimumSize sets a lower bound on the rendered width and must be positive.

Source

Thrown at src/Spectre.Console/Widgets/Layout/Layout.cs:55

            _ratio = value;
        }
    }

    /// <summary>
    /// Gets or sets the minimum width.
    /// </summary>
    /// <remarks>
    /// Defaults to <c>1</c>.
    /// Must be greater than <c>0</c>.
    /// </remarks>
    public int MinimumSize
    {
        get => _minimumSize;
        set
        {
            if (value < 1)
            {
                throw new InvalidOperationException("Minimum size must be equal to or greater than 1");
            }

            _minimumSize = value;
        }
    }

    /// <summary>
    /// Gets or sets the width.
    /// </summary>
    /// <remarks>
    /// Defaults to <c>null</c>.
    /// Must be greater than <c>0</c>.
    /// </remarks>
    public int? Size
    {
        get => _size;
        set
        {

View on GitHub (pinned to 0acc92fada)

Solutions

  1. Set MinimumSize to a positive integer >= 1.
  2. Omit setting MinimumSize to keep the default of 1 when no explicit minimum is needed.
  3. Guard computed values with Math.Max(1, value).

Example fix

// before
layout.MinimumSize = measuredMin; // could be 0

// after
layout.MinimumSize = Math.Max(1, measuredMin);
Defensive patterns

Strategy: validation

Validate before calling

if (value < 1) throw new ArgumentOutOfRangeException(nameof(value), "MinimumSize must be >= 1");
layout.MinimumSize = value;

Type guard

static bool IsValidMinimumSize(int value) => value >= 1;

Prevention

When it happens

Trigger: Assigning MinimumSize a value of 0 or a negative number.

Common situations: Setting MinimumSize to 0 to mean 'no minimum' (the library does not support that; leave the default), or computing it from a measurement that yields 0.

Related errors


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