{"record":{"id":"f9eb48a134387eac","repo":"dotnet/machinelearning","slug":"strings-indexisgreaterthancolumnlength-f9eb48","errorCode":null,"errorMessage":"Strings.IndexIsGreaterThanColumnLength","messagePattern":"Strings\\.IndexIsGreaterThanColumnLength","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs","lineNumber":354,"sourceCode":"            ReadOnlyDataFrameBuffer<byte> bitMapBuffer = NullBitMapBuffers[bitMapIndex];\n\n            // Get the bit\n            index -= bitMapIndex * ReadOnlyDataFrameBuffer<T>.MaxCapacity;\n            int bitMapBufferIndex = (int)((uint)index / 8);\n            Debug.Assert(bitMapBuffer.Length > bitMapBufferIndex);\n            byte curBitMap = bitMapBuffer[bitMapBufferIndex];\n            return BitUtility.IsBitSet(curBitMap, (int)index);\n        }\n\n        public long Length { get; private set; }\n\n        public long NullCount { get; private set; }\n\n        public int GetIndexOfBufferContainingRowIndex(long rowIndex)\n        {\n            if (rowIndex >= Length)\n            {\n                throw new ArgumentOutOfRangeException(Strings.IndexIsGreaterThanColumnLength, nameof(rowIndex));\n            }\n            return (int)(rowIndex / ReadOnlyDataFrameBuffer<T>.MaxCapacity);\n        }\n\n        internal int MaxRecordBatchLength(long startIndex)\n        {\n            if (Length == 0)\n                return 0;\n            int bufferIndex = GetIndexOfBufferContainingRowIndex(startIndex);\n            startIndex = startIndex - bufferIndex * ReadOnlyDataFrameBuffer<T>.MaxCapacity;\n            return Buffers[bufferIndex].Length - (int)startIndex;\n        }\n\n        public IReadOnlyList<T?> this[long startIndex, int length]\n        {\n            get\n            {\n                var ret = new List<T?>(length);","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs#L336-L372","documentation":"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.","triggerScenarios":"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.","commonSituations":"Using a row index from another (longer) column or DataFrame, stale indices after truncation, or looping to column.Length inclusive.","solutions":["Check rowIndex >= 0 && rowIndex < column.Length before indexing; fix the source of the out-of-range index.","Recompute indices from the current column (use GetRow/GetTypedRow or foreach over values) instead of mixing indices across columns.","If you intended a position beyond the data, resize the column first rather than indexing past Length."],"exampleFix":"// before\nvar value = column[100]; // column.Length == 50\n// after\nif (rowIndex >= 0 && rowIndex < column.Length)\n{\n    var value = column[rowIndex];\n}","handlingStrategy":"validation","validationCode":"if (rowIndex >= 0 && rowIndex < column.Length) { var v = column[rowIndex]; }","typeGuard":"static bool HasRow(PrimitiveDataFrameColumn<T> col, long rowIndex) => rowIndex >= 0 && rowIndex < col.Length;","tryCatchPattern":"try { var v = column[rowIndex]; }\ncatch (ArgumentOutOfRangeException)\n{\n    // index came from a different-length source; recompute or clamp\n}","preventionTips":["Never reuse row indices across columns of different lengths","Enumerate with foreach/GetRow instead of raw indices when possible","After truncation or filtering, refresh indices from the current column"],"tags":["argumentoutofrange","row-index","dataframe","buffer"],"backgroundTag":"index-out-of-range","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}