{"record":{"id":"72db2bb9ad7af3af","repo":"stride3d/stride","slug":"array-is-multi-dimensional","errorCode":null,"errorMessage":"array is multi-dimensional","messagePattern":"array is multi-dimensional","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/Collections/SortedList.cs","lineNumber":373,"sourceCode":"            return;\n        var i = IndexOfKey(key1);\n        if (i >= 0) RemoveAt(i);\n    }\n\n    // ICollection\n\n    void ICollection.CopyTo(Array array, int arrayIndex)\n    {\n        if (Count == 0)\n            return;\n\n        ArgumentNullException.ThrowIfNull(array);\n\n        if (arrayIndex < 0)\n            throw new ArgumentOutOfRangeException();\n\n        if (array.Rank > 1)\n            throw new ArgumentException(\"array is multi-dimensional\");\n        if (arrayIndex >= array.Length)\n            throw new ArgumentNullException(\"arrayIndex is greater than or equal to array.Length\");\n        if (Count > (array.Length - arrayIndex))\n            throw new ArgumentNullException(\"Not enough space in array from arrayIndex to end of array\");\n\n        using var it = GetEnumerator();\n        var i = arrayIndex;\n\n        while (it.MoveNext())\n        {\n            array.SetValue(it.Current, i++);\n        }\n    }\n\n    //\n    // SortedList<TKey, TValue>\n    //\n","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/Collections/SortedList.cs#L355-L391","documentation":"This CopyTo overload validates that the destination array is one-dimensional (array.Rank <= 1) before writing, because element-by-element indexing cannot address multi-dimensional arrays. A multi-dimensional array (e.g. T[,] ) triggers this ArgumentException.","triggerScenarios":"Calling the non-explicit-interface CopyTo(new T[2,2], 0) or any array with Rank > 1.","commonSituations":"Passing a rectangular 2D grid buffer because its total Length looks sufficient, or generic code that receives Array and does not check Rank.","solutions":["Pass a one-dimensional array: var flat = new KeyValuePair<TKey,TValue>[sl.Count].","If you need 2D layout, copy into a flat 1D array first and then map indices yourself.","Add array.Rank == 1 check in generic helper code before calling CopyTo."],"exampleFix":"// before\nvar grid = new KeyValuePair<string,int>[2, 2];\nsl.CopyTo(grid, 0);\n// after\nvar flat = new KeyValuePair<string,int>[sl.Count];\nsl.CopyTo(flat, 0);","handlingStrategy":"type-guard","validationCode":"if (array == null || array.Rank != 1)\n    throw new ArgumentException(\"Destination must be a 1D array.\", nameof(array));","typeGuard":"static bool Is1DKvpArray(object a) =>\n    a is KeyValuePair<TKey,TValue>[] and { Rank: 1 };","tryCatchPattern":"try { sortedList.CopyTo(array, arrayIndex); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"multi-dimensional\"))\n{ var flat = new KeyValuePair<TKey,TValue>[sortedList.Count]; sortedList.CopyTo(flat, 0); }","preventionTips":["Keep the destination as KeyValuePair<TKey,TValue>[] (jagged/1D), never T[,].","In generic helpers accepting Array, assert Rank == 1 before CopyTo.","Flatten multi-dimensional data into 1D buffers first."],"tags":["collections","argument-validation","multi-dimensional-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"}