{"record":{"id":"543908c5ffa20b01","repo":"stride3d/stride","slug":"argumentoutofrangeexception","errorCode":null,"errorMessage":"ArgumentOutOfRangeException","messagePattern":"ArgumentOutOfRangeException","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/SortedDictionary.cs","lineNumber":539,"sourceCode":"            {\n                return new Enumerator(dictionary);\n            }\n\n            IEnumerator IEnumerable.GetEnumerator()\n            {\n                return new Enumerator(dictionary);\n            }\n\n            public void CopyTo(TKey[] array, int index)\n            {\n                if (array == null)\n                {\n                    throw new ArgumentNullException();\n                }\n\n                if (index < 0)\n                {\n                    throw new ArgumentOutOfRangeException();\n                }\n\n                if (array.Length - index < Count)\n                {\n                    throw new ArgumentException();\n                }\n\n                dictionary._set.InOrderTreeWalk(delegate(TreeSet<KeyValuePair<TKey, TValue>>.Node node)\n                {\n                    array[index++] = node.Item.Key;\n                    return true;\n                });\n            }\n\n            void ICollection.CopyTo(Array array, int index)\n            {\n                if (array == null)\n                {","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/SortedDictionary.cs#L521-L557","documentation":"Collection contract guard in SortedDictionary.KeyCollection.CopyTo: the index parameter is negative (or would place the copy out of range), so copying the keys into the destination array cannot proceed. The faulting input is the index argument.","triggerScenarios":"Calling CopyTo with a negative index, often from a computed offset that went below zero (e.g. index -= n on a small buffer).","commonSituations":"Offset arithmetic bugs when filling a section of a larger array.","solutions":["Clamp or validate index >= 0 before calling CopyTo","Recheck the offset calculation that produced the negative index","Use index 0 when copying into a fresh array"],"exampleFix":"// before\nkeys.CopyTo(arr, -1);\n// after\nif (index >= 0) keys.CopyTo(arr, index);","handlingStrategy":"validation","validationCode":"if (index < 0) throw new InvalidOperationException(\"CopyTo index must be non-negative\");","typeGuard":"null","tryCatchPattern":"try { keys.CopyTo(arr, index); } catch (ArgumentOutOfRangeException) { keys.CopyTo(arr, 0); }","preventionTips":["Validate computed offsets before CopyTo","Clamp indices with Math.Max(0, index)","Prefer ToArray() over index-based copying"],"tags":["csharp","argument-out-of-range","copy"],"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-23T08:17:48.524Z"}