{"record":{"id":"f71467dde8f5184a","repo":"stride3d/stride","slug":"index","errorCode":null,"errorMessage":"index","messagePattern":"index","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/Collections/MultiValueSortedDictionary.cs","lineNumber":283,"sourceCode":"    /// </param>\n    /// <exception cref=\"System.ArgumentNullException\">array is null.</exception>\n    /// <exception cref=\"System.ArgumentOutOfRangeException\">\n    /// index is equal to or greater than the length of array.  -or- index is less\n    /// than 0.\n    /// </exception>\n    /// <exception cref=\"System.ArgumentException\">\n    /// The number of elements in the source KoderHack.MultiValueSortedDictionary&lt;TKey,TValue&gt;\n    /// is greater than the available space from index to the end of the destination\n    /// array.\n    /// </exception>\n    public void CopyTo(KeyValuePair<TKey, TValue>[] array, int index)\n    {\n        if (array == null)\n            throw new ArgumentNullException(nameof(array));\n        if (index < 0)\n            throw new ArgumentOutOfRangeException(nameof(index));\n        if (index >= array.Length || _Count > array.Length - index)\n            throw new ArgumentException(\"index\");\n\n        var copyIndex = index;\n        foreach (var pair in this)\n            array[copyIndex++] = new KeyValuePair<TKey, TValue>(pair.Key, pair.Value);\n    }\n\n    /// <summary>\n    /// Returns an enumerator that iterates through the KoderHack.MultiValueSortedDictionary&lt;TKey,TValue&gt;.\n    /// </summary>\n    /// <returns>\n    /// A KoderHack.MultiValueSortedDictionary&lt;TKey,TValue&gt;.Enumerator for\n    /// the KoderHack.MultiValueSortedDictionary&lt;TKey,TValue&gt;.\n    /// </returns>\n    public Enumerator GetEnumerator()\n    {\n        _IsModified = false;\n        return new Enumerator(this);\n    }","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/Collections/MultiValueSortedDictionary.cs#L265-L301","documentation":"MultiValueSortedDictionary's non-generic ICollection.CopyTo validates the destination array and index, then throws ArgumentException(\"index\") when the index is at or past the array's end, or when the dictionary's element count does not fit between index and the array length. It uses ArgumentException with the message 'index' rather than a more descriptive message.","triggerScenarios":"Calling CopyTo(array, index) where index >= array.Length, or where index < array.Length but Count elements cannot fit starting at index (i.e. Count > array.Length - index).","commonSituations":"Copying into a fixed-size buffer sized without accounting for the starting offset; copying multiple collections into one array with an index that leaves too little room; passing a default-sized array.","solutions":["Allocate the array with length >= index + dictionary Count before copying","Compute required size: array = new KeyValuePair<TKey,TValue>[dict.Count + index]","Copy at index 0 into a correctly sized array when no offset is needed","Catch ArgumentException and re-copy into a larger array if you cannot pre-size"],"exampleFix":"// before\nvar arr = new KeyValuePair<TKey,TValue>[dict.Count];\ndict.CopyTo(arr, 5); // throws: 5 + Count > arr.Length\n// after\nvar arr = new KeyValuePair<TKey,TValue>[dict.Count + 5];\ndict.CopyTo(arr, 5);","handlingStrategy":"validation","validationCode":"if (array == null || index < 0 || index >= array.Length || dict.Count > array.Length - index) throw new ArgumentException(\"Array too small for CopyTo\");\ndict.CopyTo(array, index);","typeGuard":null,"tryCatchPattern":"try { dict.CopyTo(array, index); } catch (ArgumentException) { array = new KeyValuePair<TKey,TValue>[dict.Count + index]; dict.CopyTo(array, index); }","preventionTips":["Size arrays as Count + offset","Copy at index 0 when possible","Validate index bounds before CopyTo"],"tags":["csharp","collections","copyto","argument"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}