tursodatabase/turso · error · IndexOutOfRangeException

Index was outside the bounds of the array.

Error message

Index was outside the bounds of the array.

What it means

Thrown by SqliteDataReader.GetValues when the caller-supplied values array is shorter than the reader's FieldCount. Despite the CLR-default message text, this is a deliberate guard rejecting an undersized destination array before the copy loop fills it.

Source

Thrown at bindings/dotnet/src/Turso.Data.Sqlite/SqliteDataReader.cs:696

        };
    }

    public override int GetValues(object[] values)
    {
        EnsureOpen();
        if (_managedExecution is null)
        {
            _ = GetStatement();
            EnsureHasCurrentRow();
        }
        else
        {
            EnsureHasManagedCurrentRow();
        }

        ArgumentNullException.ThrowIfNull(values);
        if (values.Length < FieldCount)
            throw new IndexOutOfRangeException();

        var count = FieldCount;
        for (var i = 0; i < count; i++)
            values[i] = GetValue(i);

        return count;
    }

    public override bool IsDBNull(int ordinal)
    {
        EnsureOpen();
        if (_managedExecution is not null)
            return GetManagedValue(ordinal) == DBNull.Value;

        EnsureHasCurrentRow();
        var statement = GetStatement();
        var valueType = TursoBindings.GetValue(statement, ordinal).ValueType;
        return valueType is TursoValueType.Null or TursoValueType.Empty;

View on GitHub (pinned to 6c72522679)

Solutions

  1. Allocate the array as new object[reader.FieldCount] before calling GetValues
  2. Pass an array at least as large as the number of columns in the result set
  3. Use reader.FieldCount (not a hardcoded size) to size the buffer
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at bindings/dotnet/src/Turso.Data.Sqlite/SqliteDataReader.cs:696 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tursodatabase/turso@6c72522679 (2026-09-06). Data as JSON: /api/errors/01c00e36ee8d7131. Report an issue: GitHub.