{"record":{"id":"6daa1dcffc294333","repo":"dotnet/wpf","slug":"sr-format-sr-gridcollection-destarrayinvalidlowerbound-index","errorCode":null,"errorMessage":"SR.Format(SR.GridCollection_DestArrayInvalidLowerBound, \"index\")","messagePattern":"SR\\.Format\\(SR\\.GridCollection_DestArrayInvalidLowerBound, \"index\"\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinition.cs","lineNumber":82,"sourceCode":"        //  Public Methods\n        //\n        //------------------------------------------------------\n\n        #region Public Methods\n\n        /// <summary>\n        ///     <see cref=\"ICollection.CopyTo\"/>\n        /// </summary>\n        void ICollection.CopyTo(Array array, int index)\n        {\n            ArgumentNullException.ThrowIfNull(array);\n            if (array.Rank != 1)\n            {\n                throw new ArgumentException(SR.GridCollection_DestArrayInvalidRank);\n            }\n            if (index < 0)\n            {\n                throw new ArgumentOutOfRangeException(SR.Format(SR.GridCollection_DestArrayInvalidLowerBound, \"index\"));\n            }\n            if (array.Length - index < _size)\n            {\n                throw new ArgumentException(SR.Format(SR.GridCollection_DestArrayInvalidLength, \"array\"));\n            }\n\n            if (_size > 0)\n            {\n                Debug.Assert(_items != null);\n                Array.Copy(_items, 0, array, index, _size);\n            }\n        }\n\n        /// <summary>\n        ///     <see cref=\"ICollection<T>.CopyTo\"/>\n        /// </summary>\n        public void CopyTo(ColumnDefinition[] array, int index) //  void ICollection<T>.CopyTo(T[] array, int arrayIndex)\n        {","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinition.cs#L64-L100","documentation":"The explicit ICollection.CopyTo on ColumnDefinitionCollection requires the index parameter to be non-negative. A negative index throws ArgumentOutOfRangeException with SR.GridCollection_DestArrayInvalidLowerBound (parameter \"index\").","triggerScenarios":"Calling ((ICollection)grid.ColumnDefinitions).CopyTo(array, -1) or with a negative computed offset (e.g. index = cursor where cursor went below zero).","commonSituations":"Chained copies with a moving offset that underflows; passing an uninitialized/default int or a subtraction result like remaining - copied that turned negative.","solutions":["Ensure index >= 0 before calling; clamp or assert on the value.","Fix the offset calculation that produces the negative index.","If copying from scratch, use index 0 into a correctly sized array."],"exampleFix":"// before\nint idx = itemsCopied - batch; // can be negative\n((ICollection)defs).CopyTo(target, idx);\n// after\nint idx = Math.Max(0, itemsCopied);\nif (idx + defs.Count <= target.Length)\n    ((ICollection)defs).CopyTo(target, idx);","handlingStrategy":"validation","validationCode":"if (index < 0) throw new ArgumentOutOfRangeException(nameof(index));","typeGuard":"static bool IsValidCopyIndex(int i) => i >= 0;","tryCatchPattern":"try { ((ICollection)defs).CopyTo(array, index); }\ncatch (ArgumentOutOfRangeException) { ((ICollection)defs).CopyTo(array, 0); }","preventionTips":["Assert offsets are non-negative before chained copies","Track copy cursors with checked arithmetic","Default index to 0 for fresh buffers"],"tags":["wpf","grid","array","argument-out-of-range"],"backgroundTag":"index-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}