{"record":{"id":"9c6558093c412af3","repo":"AvaloniaUI/Avalonia","slug":"multi-dimensional-arrays-are-not-supported","errorCode":null,"errorMessage":"Multi-dimensional arrays are not supported.","messagePattern":"Multi-dimensional arrays are not supported\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Collections/AvaloniaList.cs","lineNumber":666,"sourceCode":"        }\n\n        /// <inheritdoc/>\n        void IList.RemoveAt(int index)\n        {\n            RemoveAt(index);\n        }\n\n        /// <inheritdoc/>\n        void ICollection.CopyTo(Array array, int index)\n        {\n            if (array == null)\n            {\n                throw new ArgumentNullException(nameof(array));\n            }\n\n            if (array.Rank != 1)\n            {\n                throw new ArgumentException(\"Multi-dimensional arrays are not supported.\");\n            }\n\n            if (array.GetLowerBound(0) != 0)\n            {\n                throw new ArgumentException(\"Non-zero lower bounds are not supported.\");\n            }\n\n            if (index < 0)\n            {\n                throw new ArgumentException(\"Invalid index.\");\n            }\n\n            if (array.Length - index < Count)\n            {\n                throw new ArgumentException(\"The target array is too small.\");\n            }\n\n            if (array is T[] tArray)","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Collections/AvaloniaList.cs#L648-L684","documentation":"ArgumentException thrown by AvaloniaList.ICollection.CopyTo when the destination array has Rank != 1 (i.e. it is multi-dimensional, like T[,]). The non-generic CopyTo only supports single-dimensional arrays.","triggerScenarios":"Passing a multi-dimensional array such as 'new T[rows, cols]' to ((ICollection)list).CopyTo(array, index).","commonSituations":"Interop code or serializers that allocate a 2D array and attempt to flatten a list into it; matrix/grid helpers misusing CopyTo.","solutions":["Allocate a single-dimensional array (new T[list.Count]) for the destination.","If you need a 2D layout, copy into a 1D array then index manually into the 2D structure.","Validate array.Rank == 1 before invoking CopyTo."],"exampleFix":"// before\nvar dest = new T[10, 10];\n((ICollection)list).CopyTo(dest, 0);\n\n// after\nvar dest = new T[list.Count];\n((ICollection)list).CopyTo(dest, 0);","handlingStrategy":"validation","validationCode":"if (array.Rank != 1) throw new ArgumentException(\"Use a 1D array.\", nameof(array));","typeGuard":"static bool IsSingleDimensional(Array a) => a.Rank == 1;","tryCatchPattern":null,"preventionTips":["Allocate single-dimensional arrays for CopyTo destinations.","Validate array.Rank before copying.","Avoid flattening into 2D buffers via CopyTo."],"tags":["avalonia","collections","list","copyto","array-validation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}