{"record":{"id":"e580ab0eac83fc63","repo":"dotnet/machinelearning","slug":"nameof-index","errorCode":null,"errorMessage":"nameof(index)","messagePattern":"nameof\\(index\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs","lineNumber":311,"sourceCode":"        {\n            int bitMapBufferIndex = (int)((uint)index / 8);\n            Debug.Assert(bitMapBufferSpan.Length >= bitMapBufferIndex);\n            byte curBitMap = bitMapBufferSpan[bitMapBufferIndex];\n            byte newBitMap = SetBit(curBitMap, index, value);\n            bitMapBufferSpan[bitMapBufferIndex] = newBitMap;\n        }\n\n        /// <summary>\n        /// A null value has an unset bit\n        /// A NON-null value has a set bit\n        /// </summary>\n        /// <param name=\"index\"></param>\n        /// <param name=\"value\"></param>\n        internal void SetValidityBit(long index, bool value)\n        {\n            if ((ulong)index > (ulong)Length)\n            {\n                throw new ArgumentOutOfRangeException(nameof(index));\n            }\n            // First find the right bitMapBuffer\n            int bitMapIndex = (int)(index / ReadOnlyDataFrameBuffer<T>.MaxCapacity);\n            Debug.Assert(NullBitMapBuffers.Count > bitMapIndex);\n            DataFrameBuffer<byte> bitMapBuffer = (DataFrameBuffer<byte>)NullBitMapBuffers[bitMapIndex];\n\n            // Set the bit\n            index -= bitMapIndex * ReadOnlyDataFrameBuffer<T>.MaxCapacity;\n            int bitMapBufferIndex = (int)((uint)index / 8);\n            Debug.Assert(bitMapBuffer.Length >= bitMapBufferIndex);\n            if (bitMapBuffer.Length == bitMapBufferIndex)\n                bitMapBuffer.Append(0);\n            SetValidityBit(bitMapBuffer.Span, (int)index, value);\n        }\n\n        private bool GetValidityBit(long index)\n        {\n            if ((uint)index >= Length)","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs#L293-L329","documentation":"SetValidityBit validates that the bit index lies within [0, Length] before writing into the null (validity) bitmap buffers. An index beyond Length (or negative) would map to a bitmap buffer/offset that does not exist, so it throws ArgumentOutOfRangeException with paramName `index`. It is internal and normally reached via Append, which grows the container as needed.","triggerScenarios":"Calling Append/AppendMany with an index-derived path where the container's Length bookkeeping is behind (e.g. appending into a container constructed with an explicit smaller length), or internal/direct calls to SetValidityBit(index, value) with index > Length or index < 0.","commonSituations":"Manually extending a container after constructing it from a prebuilt bitmap with a length smaller than the data being appended, off-by-one loops that call append one time too many, or custom column subclasses that bypass AppendMany's growth.","solutions":["Ensure the container Length covers the target index first: call Resize(index) or use Append, which grows buffers automatically.","Verify loops append at most Length values and that indices are long, non-negative, and zero-based.","If constructing from a raw bitmap, pass the true final row count as `length` so subsequent appends start at the right index."],"exampleFix":"// before\ncontainer.SetValidityBit(container.Length + 5, true); // out of range\n// after\ncontainer.Resize(container.Length + 6);\ncontainer.SetValidityBit(container.Length - 1, true);","handlingStrategy":"validation","validationCode":"if (index < 0 || index > container.Length) throw new InvalidOperationException(\"index out of range for SetValidityBit\");","typeGuard":"static bool CanSetValidityBit<T>(PrimitiveColumnContainer<T> c, long index) => (ulong)index <= (ulong)c.Length;","tryCatchPattern":"try { container.SetValidityBit(index, value); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"index\")\n{\n    container.Resize(index + 1);\n    container.SetValidityBit(index, value);\n}","preventionTips":["Prefer Append/AppendMany over manual bitmap manipulation","Keep container Length in sync with data before touching validity bits","Use `i < Length` bounds in loops that touch validity bits"],"tags":["argumentoutofrange","index","null-bitmap","append"],"backgroundTag":"argument-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"}