AvaloniaUI/Avalonia · error · ArgumentNullException
array
Error message
array
What it means
ArgumentNullException thrown by the non-generic ICollection.CopyTo implementation on AvaloniaList when the destination array is null. The method copies the list's elements into the supplied System.Array.
Source
Thrown at src/Avalonia.Base/Collections/AvaloniaList.cs:661
/// <inheritdoc/>
void IList.Remove(object? value)
{
Remove((T)value!);
}
/// <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)View on GitHub (pinned to 11c5427268)
Solutions
- Allocate a correctly-sized destination array before calling CopyTo (e.g. new T[list.Count]).
- Prefer the strongly-typed list.CopyTo(T[] array, int index) overload which has its own checks.
- Null-check the array and skip/throw a meaningful error upstream.
Example fix
// before ((ICollection)list).CopyTo(null, 0); // after var arr = new T[list.Count]; ((ICollection)list).CopyTo(arr, 0);
Defensive patterns
Strategy: validation
Validate before calling
_ = array ?? throw new ArgumentNullException(nameof(array));
Prevention
- Allocate the destination array before calling CopyTo.
- Prefer the strongly-typed CopyTo(T[], int) overload.
- Null-check array at the call boundary.
When it happens
Trigger: Calling ((ICollection)list).CopyTo(null, index) or ((Array)null, ...) via the non-generic ICollection interface; frameworks/collection adapters passing a null destination array.
Common situations: Interop with code that allocates the destination array conditionally and forwards null on failure; an IList/ICollection adapter that does not allocate before calling CopyTo.
Related errors
- items
- Multi-dimensional arrays are not supported.
- Non-zero lower bounds are not supported.
- Invalid index.
- The target array is too small.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/d3b3127c20da5e38.
Report an issue: GitHub.