{"record":{"id":"763676e776cd88b3","repo":"egametang/ET","slug":"argument-incompatiblearraytype","errorCode":null,"errorMessage":"Argument_IncompatibleArrayType","messagePattern":"Argument_IncompatibleArrayType","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Collection/SortedSet.cs","lineNumber":721,"sourceCode":"                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));\n                }\n\n                try\n                {\n                    InOrderTreeWalk(node =>\n                    {\n                        objects[index++] = node.Item;\n                        return true;\n                    });\n                }\n                catch (ArrayTypeMismatchException)\n                {\n                    throw new ArgumentException(SR.Argument_IncompatibleArrayType, nameof(array));\n                }\n            }\n        }\n\n        #endregion","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Collection/SortedSet.cs#L703-L739","documentation":"Standard .NET BCL argument error from SortedSet<T>.CopyTo: the destination array is neither a T[] nor an object[] (after the T[] fast path failed), so there is no compatible element storage to copy into. This branch covers incompatible array ranks/element types caught before assignment.","triggerScenarios":"Passing an array whose runtime element type is neither T nor object (e.g. copying SortedSet<int> into a uint[], or a base-type array the runtime rejects), or a multidimensional array that already failed the rank check upstream and reaches here.","commonSituations":"Covariant/contravariant array mistakes; copying a value-type set into an array declared as a different numeric type; passing Array.CreateInstance with a non-matching element type.","solutions":["Allocate the destination as exactly T[]: `var arr = new T[set.Count];`.","If you must copy to object[], ensure T is a reference type (covariance); value-type sets cannot be copied into object[] via this path.","Convert element types explicitly after copying into a correctly typed array."],"exampleFix":"// before\nvar dest = new uint[set.Count];\n((ICollection<int>)set).CopyTo(dest, 0); // SortedSet<int> -> uint[] rejected\n// after\nvar dest = new int[set.Count];\nset.CopyTo(dest, 0);","handlingStrategy":"validation","validationCode":"static void CopyToTyped<T>(SortedSet<T> set, Array array, int index)\n{\n    if (!(array is T[]) && !(array is object[]))\n        throw new ArgumentException(\"array must be T[] or object[]\", nameof(array));\n    set.CopyTo((T[])array, index);\n}","typeGuard":"static bool IsCompatibleArray<T>(Array a) => a is T[] || a is object[];","tryCatchPattern":null,"preventionTips":["Allocate the destination as exactly T[].","Remember value-type sets cannot be copied into object[].","Convert element types explicitly after a correctly typed copy."],"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"}