{"record":{"id":"0b538ca35746bc0e","repo":"tursodatabase/turso","slug":"column-ordinal-ordinal-is-out-of-range","errorCode":null,"errorMessage":"column ordinal {ordinal} is out of range","messagePattern":"column ordinal (.+?) is out of range","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoRemoteDataReader.cs","lineNumber":314,"sourceCode":"            if (_results.Count == 0)\n                throw new InvalidOperationException(\"The data reader has no result sets.\");\n\n            return _results[_resultIndex];\n        }\n    }\n\n    private bool HasCurrentRow => _rowIndex >= 0 && _rowIndex < CurrentResult.Rows.Count;\n\n    private RemoteResponseValue CurrentValue(int ordinal)\n    {\n        EnsureOpen();\n        if (!HasCurrentRow)\n            throw new InvalidOperationException(\"No current row. Call Read before accessing values.\");\n\n        ValidateOrdinal(ordinal);\n        var row = CurrentResult.Rows[_rowIndex];\n        if (ordinal >= row.Count)\n            throw new IndexOutOfRangeException($\"column ordinal {ordinal} is out of range\");\n\n        return row[ordinal];\n    }\n\n    private static long CopyArray<T>(T[] source, long dataOffset, T[]? buffer, int bufferOffset, int length)\n    {\n        ArgumentOutOfRangeException.ThrowIfNegative(dataOffset);\n        ArgumentOutOfRangeException.ThrowIfNegative(bufferOffset);\n        ArgumentOutOfRangeException.ThrowIfNegative(length);\n\n        if (dataOffset >= source.LongLength)\n            return 0;\n\n        var available = source.LongLength - dataOffset;\n\n        if (buffer is null)\n            return available;\n","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data/TursoRemoteDataReader.cs#L296-L332","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// keep ordinals within the declared columns\nif (ordinal >= 0 && ordinal < reader.FieldCount)\n    var value = reader.GetValue(ordinal);","typeGuard":null,"tryCatchPattern":"try { var v = reader.GetValue(ord); }\ncatch (IndexOutOfRangeException) { /* row shorter than columns: protocol-level defect; log and stop */ }","preventionTips":["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."],"tags":["dotnet","ado-net","ordinal","protocol-invariant"],"backgroundTag":"ordinal-out-of-range","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}