dotnet/machinelearning · error · ArgumentOutOfRangeException

Strings.IndexIsGreaterThanColumnLength

Error message

Strings.IndexIsGreaterThanColumnLength

What it means

Like the string column, VBufferDataFrameColumn<T> shards its rows into MaxCapacity-sized buffers; GetBufferIndexContainingRowIndex throws ArgumentOutOfRangeException when rowIndex >= Length because no buffer holds that row.

Source

Thrown at src/Microsoft.Data.Analysis/DataFrameColumns/VBufferDataFrameColumn.cs:86

        }

        public void Append(VBuffer<T> value)
        {
            List<VBuffer<T>> lastBuffer = _vBuffers[_vBuffers.Count - 1];
            if (lastBuffer.Count == MaxCapacity)
            {
                lastBuffer = new List<VBuffer<T>>();
                _vBuffers.Add(lastBuffer);
            }
            lastBuffer.Add(value);
            Length++;
        }

        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)
        {
            return GetTypedValue(rowIndex);
        }

        protected VBuffer<T> GetTypedValue(long rowIndex)
        {
            int bufferIndex = GetBufferIndexContainingRowIndex(rowIndex);
            return _vBuffers[bufferIndex][(int)(rowIndex % MaxCapacity)];
        }

        protected override IReadOnlyList<object> GetValues(long startIndex, int length)
        {

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Validate rowIndex < Length before indexing
  2. Fix loop bounds to strict less-than
  3. Populate/Resize the column before reading
  4. Catch ArgumentOutOfRangeException at boundaries where lengths are dynamic

Example fix

// before
var v = column[column.Length];
// after
var v = rowIndex < column.Length ? column[rowIndex] : default(VBuffer<T>);
Defensive patterns

Strategy: validation

Validate before calling

if (rowIndex < 0 || rowIndex >= column.Length) throw new ArgumentOutOfRangeException(nameof(rowIndex));

Type guard

bool IsValidVBufferIndex(long i, long length) => i >= 0 && i < length;

Try / catch

try { var v = column[rowIndex]; } catch (ArgumentOutOfRangeException) { /* row absent; use default buffer */ }

Prevention

When it happens

Trigger: Object indexer get or bufferIndex call with rowIndex beyond the column's Length; reading a row from an empty column.

Common situations: Enumerating with i <= Length off-by-one; column not yet populated but reader assumes final size; mismatched DataFrame row counts.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/5061a393cc06cfc9. Report an issue: GitHub.