spectreconsole/spectre.console · error · IndexOutOfRangeException

Table column index cannot exceed the number of rows in the…

Error message

Table column index cannot exceed the number of rows in the table.

What it means

In TableRowCollection.Update, if column >= the row's renderable count it throws IndexOutOfRangeException. NOTE: the thrown message says 'Table column index cannot exceed the number of ROWS in the table' — this is a copy-paste bug in the message text; it actually guards the column bound, not rows.

Solutions

  1. Check column < table.Columns.Count (and column >= 0) before calling Update.
  2. When debugging, ignore the misleading 'rows' word in the message — verify the column index.
  3. Recompute column indices after structural column changes.

Example fix

// before
table.Rows.Update(rowIndex, colIndex, cell); // colIndex == Columns.Count

// after
if (colIndex >= 0 && colIndex < table.Columns.Count)
    table.Rows.Update(rowIndex, colIndex, cell);
Defensive patterns

Strategy: validation

Validate before calling

if (column < 0 || column >= table.Columns.Count) return; // or throw
table.Rows.Update(row, column, cell);

Prevention

When it happens

Trigger: Calling Update with a column index >= the number of columns in that row (e.g. column == table.Columns.Count, or referencing a column that does not exist).

Common situations: Using table.Columns.Count as a valid index (it is one-past-last); stale column index after AddColumn/RemoveColumn; assuming a row has more columns than defined; confusing zero-based vs count when mapping data to columns.

Related errors


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

Appendix: source

Thrown at src/Spectre.Console/Widgets/Table/TableRowCollection.cs:110

            if (row < 0)
            {
                throw new IndexOutOfRangeException("Table row index cannot be negative.");
            }
            else if (row >= _list.Count)
            {
                throw new IndexOutOfRangeException("Table row index cannot exceed the number of rows in the table.");
            }

            var tableRow = _list.ElementAt(row);
            var currentRenderables = tableRow.ToList();

            if (column < 0)
            {
                throw new IndexOutOfRangeException("Table column index cannot be negative.");
            }
            else if (column >= currentRenderables.Count)
            {
                throw new IndexOutOfRangeException("Table column index cannot exceed the number of rows in the table.");
            }

            currentRenderables.RemoveAt(column);

            currentRenderables.Insert(column, cellData);

            var newTableRow = new TableRow(currentRenderables);

            _list.RemoveAt(row);

            _list.Insert(row, newTableRow);
        }
    }

    /// <summary>
    /// Removes a row at the specified index.
    /// </summary>
    /// <param name="index">The index to remove a row at.</param>

View on GitHub (pinned to 0acc92fada)