{"record":{"id":"5beb24fd33ecd3ca","repo":"egametang/ET","slug":"argumentoutofrange-index","errorCode":null,"errorMessage":"ArgumentOutOfRange_Index","messagePattern":"ArgumentOutOfRange_Index","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Collection/SortedSet.cs","lineNumber":703,"sourceCode":"        }\n\n        void ICollection.CopyTo(Array array, int index)\n        {\n            ArgumentNullException.ThrowIfNull(array);\n\n            if (array.Rank != 1)\n            {\n                throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));\n            }\n\n            if (array.GetLowerBound(0) != 0)\n            {\n                throw new ArgumentException(SR.Arg_NonZeroLowerBound, nameof(array));\n            }\n\n            if (index < 0 || index > array.Length)\n            {\n                throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index);\n            }\n\n            if (array.Length - index < Count)\n            {\n                throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);\n            }\n\n            T[] tarray = array as T[];\n            if (tarray != null)\n            {\n                CopyTo(tarray, index);\n            }\n            else\n            {\n                object[] objects = array as object[];\n                if (objects == null)\n                {\n                    throw new ArgumentException(SR.Argument_IncompatibleArrayType, nameof(array));","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Collection/SortedSet.cs#L685-L721","documentation":"Standard .NET BCL argument error, ported into this SortedSet<T>.CopyTo(T[] array, int index) implementation: the supplied index is negative or greater than array.Length. Mirrors the runtime SortedSet contract for the destination-array start offset.","triggerScenarios":"Calling CopyTo with index < 0 (e.g. -1) or index > array.Length (e.g. passing array.Length + 1, or index == array.Length when array is non-empty and a non-zero count must be written).","commonSituations":"Off-by-one when computing an offset; passing a base offset from another array's Length into a smaller destination; reusing an index variable from a different loop.","solutions":["Ensure 0 <= index <= array.Length, and that index leaves room for Count elements.","Prefer the single-arg CopyTo(array) overload when writing from the start.","Validate the offset against the destination array's actual Length, not a source collection's count."],"exampleFix":"// before\nset.CopyTo(dest, dest.Length); // index > allowed when dest non-empty\n// after\nset.CopyTo(dest, 0);","handlingStrategy":"validation","validationCode":"static void CopyToSafe<T>(SortedSet<T> set, T[] array, int index)\n{\n    if (index < 0 || index > array.Length) throw new ArgumentOutOfRangeException(nameof(index));\n    if (array.Length - index < set.Count) throw new ArgumentException(\"destination too small\");\n    set.CopyTo(array, index);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always bounds-check index against the destination array, not the source.","Prefer CopyTo(array, 0) or ToArray() when writing from the start.","Wrap copy sites in a helper that validates before calling."],"tags":["csharp","unity","core","collection","sortedset","argument"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}