tursodatabase/turso · error · IndexOutOfRangeException
column ordinal {ordinal} is out of range
Error message
column ordinal {ordinal} is out of range What it means
CurrentValue validates the ordinal twice: first against FieldCount (the result-set column count), then against the actual row's cell count. This error means the ordinal was valid for the declared columns but the current row carries fewer cells than the result set declares — a mismatch between RemoteStatementResult.Columns and Rows[i] that a well-formed remote response never exhibits.
Source
Thrown at bindings/dotnet/src/Turso.Data/TursoRemoteDataReader.cs:314
if (_results.Count == 0)
throw new InvalidOperationException("The data reader has no result sets.");
return _results[_resultIndex];
}
}
private bool HasCurrentRow => _rowIndex >= 0 && _rowIndex < CurrentResult.Rows.Count;
private RemoteResponseValue CurrentValue(int ordinal)
{
EnsureOpen();
if (!HasCurrentRow)
throw new InvalidOperationException("No current row. Call Read before accessing values.");
ValidateOrdinal(ordinal);
var row = CurrentResult.Rows[_rowIndex];
if (ordinal >= row.Count)
throw new IndexOutOfRangeException($"column ordinal {ordinal} is out of range");
return row[ordinal];
}
private static long CopyArray<T>(T[] source, long dataOffset, T[]? buffer, int bufferOffset, int length)
{
ArgumentOutOfRangeException.ThrowIfNegative(dataOffset);
ArgumentOutOfRangeException.ThrowIfNegative(bufferOffset);
ArgumentOutOfRangeException.ThrowIfNegative(length);
if (dataOffset >= source.LongLength)
return 0;
var available = source.LongLength - dataOffset;
if (buffer is null)
return available;
View on GitHub (pinned to 6c72522679)
Solutions
- First confirm you are not simply passing a too-large ordinal (that raises the sibling check against FieldCount); log FieldCount and the ordinal.
- If you build RemoteStatementResult in tests or a custom transport, ensure every row has exactly Columns.Count entries.
- Update the client package so bindings and protocol framing match the server version.
- If it reproduces against a real server with matching versions, capture the SQL plus response and report it as a bug with the client/server versions.
Defensive patterns
Strategy: validation
Validate before calling
// keep ordinals within the declared columns
if (ordinal >= 0 && ordinal < reader.FieldCount)
var value = reader.GetValue(ordinal); Try / catch
try { var v = reader.GetValue(ord); }
catch (IndexOutOfRangeException) { /* row shorter than columns: protocol-level defect; log and stop */ } Prevention
- Iterate columns via FieldCount instead of hardcoded ordinals.
- Keep client bindings and server versions aligned.
- When mocking RemoteStatementResult, give every row exactly Columns.Count cells.
When it happens
Trigger: A remote/batch response whose row arrays are shorter than the declared column list; hand-built RemoteStatementResult objects in tests or mocks with truncated rows; a client/server version mismatch that changes how rows are framed.
Common situations: This is effectively an internal invariant breach, not ordinary user input: it shows up when mocking the remote protocol, after a protocol/binding version skew, or from a genuine server bug. Normal user mistakes surface as the ValidateOrdinal variant of this message instead.
Related errors
- Turso batch execution is currently supported only for remote
- SqliteBlob requires an open connection.
- TursoBatchCommand only supports CommandType.Text.
- Batch command must be a TursoBatchCommand.
- TursoCommand only supports CommandType.Text.
AI-assisted analysis of tursodatabase/turso@6c72522679 (2026-08-20).
Data as JSON: /api/errors/0b538ca35746bc0e.
Report an issue: GitHub.