dotnet/machinelearning · error · ArgumentOutOfRangeException

Strings.IndexIsGreaterThanColumnLength

Error message

Strings.IndexIsGreaterThanColumnLength

What it means

GetIndexOfBufferContainingRowIndex maps a row index to the index of the internal data buffer that stores it, dividing by MaxCapacity rows per buffer. A rowIndex >= Length has no owning buffer, so the method throws ArgumentOutOfRangeException; note the message string is passed as the exception's `message` argument while nameof(rowIndex) becomes the paramName, so the message shows the localized string.

Source

Thrown at src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs:354

            ReadOnlyDataFrameBuffer<byte> bitMapBuffer = NullBitMapBuffers[bitMapIndex];

            // Get the bit
            index -= bitMapIndex * ReadOnlyDataFrameBuffer<T>.MaxCapacity;
            int bitMapBufferIndex = (int)((uint)index / 8);
            Debug.Assert(bitMapBuffer.Length > bitMapBufferIndex);
            byte curBitMap = bitMapBuffer[bitMapBufferIndex];
            return BitUtility.IsBitSet(curBitMap, (int)index);
        }

        public long Length { get; private set; }

        public long NullCount { get; private set; }

        public int GetIndexOfBufferContainingRowIndex(long rowIndex)
        {
            if (rowIndex >= Length)
            {
                throw new ArgumentOutOfRangeException(Strings.IndexIsGreaterThanColumnLength, nameof(rowIndex));
            }
            return (int)(rowIndex / ReadOnlyDataFrameBuffer<T>.MaxCapacity);
        }

        internal int MaxRecordBatchLength(long startIndex)
        {
            if (Length == 0)
                return 0;
            int bufferIndex = GetIndexOfBufferContainingRowIndex(startIndex);
            startIndex = startIndex - bufferIndex * ReadOnlyDataFrameBuffer<T>.MaxCapacity;
            return Buffers[bufferIndex].Length - (int)startIndex;
        }

        public IReadOnlyList<T?> this[long startIndex, int length]
        {
            get
            {
                var ret = new List<T?>(length);

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Check rowIndex >= 0 && rowIndex < column.Length before indexing; fix the source of the out-of-range index.
  2. Recompute indices from the current column (use GetRow/GetTypedRow or foreach over values) instead of mixing indices across columns.
  3. If you intended a position beyond the data, resize the column first rather than indexing past Length.

Example fix

// before
var value = column[100]; // column.Length == 50
// after
if (rowIndex >= 0 && rowIndex < column.Length)
{
    var value = column[rowIndex];
}
Defensive patterns

Strategy: validation

Validate before calling

if (rowIndex >= 0 && rowIndex < column.Length) { var v = column[rowIndex]; }

Type guard

static bool HasRow(PrimitiveDataFrameColumn<T> col, long rowIndex) => rowIndex >= 0 && rowIndex < col.Length;

Try / catch

try { var v = column[rowIndex]; }
catch (ArgumentOutOfRangeException)
{
    // index came from a different-length source; recompute or clamp
}

Prevention

When it happens

Trigger: Indexing into a PrimitiveDataFrameColumn (this[long rowIndex]) or calling NullCount-related lookups where rowIndex >= column.Length, or negative rowIndex (passes the unsigned-style check only if cast rules allow; negative values compared with >= Length won't throw here but callers guard) — practically, any out-of-bounds row access on the column.

Common situations: Using a row index from another (longer) column or DataFrame, stale indices after truncation, or looping to column.Length inclusive.

Related errors


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