AvaloniaUI/Avalonia · error · ArgumentException
Multi-dimensional arrays are not supported.
Error message
Multi-dimensional arrays are not supported.
What it means
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.
Source
Thrown at src/Avalonia.Base/Collections/AvaloniaList.cs:666
}
/// <inheritdoc/>
void IList.RemoveAt(int index)
{
RemoveAt(index);
}
/// <inheritdoc/>
void ICollection.CopyTo(Array array, int index)
{
if (array == null)
{
throw new ArgumentNullException(nameof(array));
}
if (array.Rank != 1)
{
throw new ArgumentException("Multi-dimensional arrays are not supported.");
}
if (array.GetLowerBound(0) != 0)
{
throw new ArgumentException("Non-zero lower bounds are not supported.");
}
if (index < 0)
{
throw new ArgumentException("Invalid index.");
}
if (array.Length - index < Count)
{
throw new ArgumentException("The target array is too small.");
}
if (array is T[] tArray)View on GitHub (pinned to 11c5427268)
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.
Example fix
// before var dest = new T[10, 10]; ((ICollection)list).CopyTo(dest, 0); // after var dest = new T[list.Count]; ((ICollection)list).CopyTo(dest, 0);
Defensive patterns
Strategy: validation
Validate before calling
if (array.Rank != 1) throw new ArgumentException("Use a 1D array.", nameof(array)); Type guard
static bool IsSingleDimensional(Array a) => a.Rank == 1;
Prevention
- Allocate single-dimensional arrays for CopyTo destinations.
- Validate array.Rank before copying.
- Avoid flattening into 2D buffers via CopyTo.
When it happens
Trigger: Passing a multi-dimensional array such as 'new T[rows, cols]' to ((ICollection)list).CopyTo(array, index).
Common situations: Interop code or serializers that allocate a 2D array and attempt to flatten a list into it; matrix/grid helpers misusing CopyTo.
Related errors
- Non-zero lower bounds are not supported.
- array
- Invalid index.
- The target array is too small.
- Invalid array type
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/9c6558093c412af3.
Report an issue: GitHub.