dotnet/machinelearning · error · ArgumentOutOfRangeException
Strings.IndexIsGreaterThanColumnLength
Error message
Strings.IndexIsGreaterThanColumnLength
What it means
StringDataFrameColumn stores rows in fixed-capacity buffers; GetBufferIndexContainingRowIndex maps a logical row index to a buffer. It throws ArgumentOutOfRangeException when rowIndex >= the column's Length, i.e. you asked for a row that does not exist in this column.
Source
Thrown at src/Microsoft.Data.Analysis/DataFrameColumns/StringDataFrameColumn.cs:107
{
var column = inPlace ? this : Clone();
for (long i = 0; i < column.Length; i++)
{
var value = column[i];
if (value != null)
column[i] = func(value);
}
return column;
}
private int GetBufferIndexContainingRowIndex(long rowIndex)
{
if (rowIndex >= Length)
{
throw new ArgumentOutOfRangeException(Strings.IndexIsGreaterThanColumnLength, nameof(rowIndex));
}
return (int)(rowIndex / MaxCapacity);
}
protected override object GetValue(long rowIndex)
{
int bufferIndex = GetBufferIndexContainingRowIndex(rowIndex);
return _stringBuffers[bufferIndex][(int)(rowIndex % MaxCapacity)];
}
protected override IReadOnlyList<object> GetValues(long startIndex, int length)
{
var ret = new List<object>();
int bufferIndex = GetBufferIndexContainingRowIndex(startIndex);
int bufferOffset = (int)(startIndex % MaxCapacity);
while (ret.Count < length && bufferIndex < _stringBuffers.Count)
{
for (int i = bufferOffset; ret.Count < length && i < _stringBuffers[bufferIndex].Count; i++)View on GitHub (pinned to 7b76e69cf9)
Solutions
- Check rowIndex against column.Length before indexing
- Ensure loops use strict less-than (i < column.Length)
- Verify the column was fully populated (same row count as the DataFrame)
- Wrap indexed access in try/catch for ArgumentOutOfRangeException in data-driven code
Example fix
// before
var value = column[column.Length];
// after
if (rowIndex >= 0 && rowIndex < column.Length)
var value = column[rowIndex]; Defensive patterns
Strategy: validation
Validate before calling
if (rowIndex < 0 || rowIndex >= column.Length) throw new ArgumentOutOfRangeException(nameof(rowIndex));
Type guard
bool IsValidIndex(long i, long length) => i >= 0 && i < length;
Try / catch
try { var v = column[rowIndex]; } catch (ArgumentOutOfRangeException) { /* handle missing row */ } Prevention
- Always compare against column.Length before indexing
- Use foreach or typed enumeration instead of manual indexing
- Watch for off-by-one loops (i < Length, not <=)
When it happens
Trigger: Accessing this[rowIndex] or bufferIndex with an index equal to or beyond the column's current row count; often from passing a 0-based index that is actually a count, or using a DataFrame with more rows than this column.
Common situations: Off-by-one loops (i <= Length), indexing after rows were removed, joining columns of mismatched lengths.
Related errors
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/859df43cd7264fbb.
Report an issue: GitHub.