{"record":{"id":"97237cac11eeebef","repo":"stride3d/stride","slug":"argumentexception","errorCode":null,"errorMessage":"ArgumentException","messagePattern":"ArgumentException","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/SortedDictionary.cs","lineNumber":544,"sourceCode":"            {\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                {\n                    throw new ArgumentNullException();\n                }\n\n                if (array.Rank != 1)\n                {","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/SortedDictionary.cs#L526-L562","documentation":"Capacity contract guard in SortedDictionary.KeyCollection.CopyTo: the destination array is too small — array.Length minus index is less than the key count — so the keys cannot all be copied into it. The faulting input is the array (or the index) passed to CopyTo.","triggerScenarios":"Calling CopyTo with an array smaller than Count minus the starting index, e.g. reusing a stale array after the dictionary grew.","commonSituations":"Caching a buffer sized from an earlier Count, then the dictionary gained entries; off-by-one when reserving space for the index offset.","solutions":["Size the array to Count + index before copying","Re-allocate the buffer each time instead of caching it","Check array.Length - index >= collection.Count before calling CopyTo"],"exampleFix":"// before\nvar arr = new TKey[keys.Count]; // stale, dict grew\nkeys.CopyTo(arr, 1);\n// after\nvar arr = new TKey[keys.Count + 1];\nkeys.CopyTo(arr, 1);","handlingStrategy":"validation","validationCode":"if (array.Length - index < keyCollection.Count) array = new TKey[keyCollection.Count + index];","typeGuard":"null","tryCatchPattern":"try { keys.CopyTo(arr, index); } catch (ArgumentException) { arr = new TKey[keys.Count + index]; keys.CopyTo(arr, index); }","preventionTips":["Size destination arrays from the live Count, not cached values","Re-allocate buffers when the collection may have changed","Assert array.Length - index >= Count before copying"],"tags":["csharp","argument","copy","array"],"backgroundTag":"invalid-argument-value","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"}