{"record":{"id":"426912355eee0c54","repo":"dotnet/machinelearning","slug":"strings-cannotresizedown-426912","errorCode":null,"errorMessage":"Strings.CannotResizeDown","messagePattern":"Strings\\.CannotResizeDown","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrameColumns/VBufferDataFrameColumn.cs","lineNumber":62,"sourceCode":"        public VBufferDataFrameColumn(string name, IEnumerable<VBuffer<T>> values) : base(name, 0, typeof(VBuffer<T>))\n        {\n            values = values ?? throw new ArgumentNullException(nameof(values));\n            if (_vBuffers.Count == 0)\n            {\n                _vBuffers.Add(new List<VBuffer<T>>());\n            }\n            foreach (var value in values)\n            {\n                Append(value);\n            }\n        }\n\n        public override long NullCount => 0;\n\n        protected internal override void Resize(long length)\n        {\n            if (length < Length)\n                throw new ArgumentException(Strings.CannotResizeDown, nameof(length));\n\n            for (long i = Length; i < length; i++)\n            {\n                Append(default);\n            }\n        }\n\n        public void Append(VBuffer<T> value)\n        {\n            List<VBuffer<T>> lastBuffer = _vBuffers[_vBuffers.Count - 1];\n            if (lastBuffer.Count == MaxCapacity)\n            {\n                lastBuffer = new List<VBuffer<T>>();\n                _vBuffers.Add(lastBuffer);\n            }\n            lastBuffer.Add(value);\n            Length++;\n        }","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrameColumns/VBufferDataFrameColumn.cs#L44-L80","documentation":"Not-implemented sentinel in VBufferDataFrameColumn.Resize: like other DataFrameColumn implementations, Resize can only extend the column (appending default VBuffer<T> entries). Requesting a length shorter than the current Length would discard rows, so the guard throws Strings.CannotResizeDown rather than truncating silently.","triggerScenarios":"Calling Resize(length) with length < column.Length; truncating a VBuffer column directly.","commonSituations":"Reusing a pooled column across batches where the new batch is smaller; resizing to match a shorter DataFrame.","solutions":["Resize only to lengths >= column.Length","Create a new VBufferDataFrameColumn<T> of the desired smaller size and copy the prefix rows","Use Slice/take operations instead of truncating in place","Track prior length and call Resize(newLength - currentLength) semantics correctly"],"exampleFix":"// before\nif (newLength < column.Length) column.Resize(newLength);\n// after\nvar trimmed = new VBufferDataFrameColumn<T>(column.Name);\nfor (long i = 0; i < newLength; i++) trimmed.Append(column[i]);","handlingStrategy":"validation","validationCode":"if (newLength < column.Length) throw new ArgumentException(\"Cannot shrink VBufferDataFrameColumn via Resize\");","typeGuard":"bool CanResizeTo(long current, long target) => target >= current;","tryCatchPattern":"try { column.Resize(newLength); } catch (ArgumentException) { /* rebuild smaller column */ }","preventionTips":["Only grow columns via Resize; create new columns to shrink","Check requested length against current Length","Avoid reusing pooled columns across differently sized batches"],"tags":["argumentexception","resize","vbuffer"],"backgroundTag":"invalid-argument-value","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}