AvaloniaUI/Avalonia · error · ArgumentException

Non-zero lower bounds are not supported.

Error message

Non-zero lower bounds are not supported.

What it means

ArgumentException thrown by AvaloniaList.ICollection.CopyTo when the destination array's lower bound is non-zero. This happens with arrays created via Array.CreateInstance with a non-zero lower bound; the implementation only supports zero-based arrays.

Source

Thrown at src/Avalonia.Base/Collections/AvaloniaList.cs:671

            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)
            {
                _inner.CopyTo(tArray, index);
            }
            else
            {

View on GitHub (pinned to 11c5427268)

Solutions

  1. Use a standard zero-based array (new T[n]) as the destination.
  2. If you must keep a non-zero-based array, copy element-by-element into the correct indices manually.
  3. Check array.GetLowerBound(0) == 0 before calling CopyTo.

Example fix

// before
var dest = Array.CreateInstance(typeof(T), new[]{10}, new[]{1});
((ICollection)list).CopyTo(dest, 1);

// after
var dest = new T[10];
((ICollection)list).CopyTo(dest, 0);
Defensive patterns

Strategy: validation

Validate before calling

if (array.GetLowerBound(0) != 0) throw new ArgumentException("Array must be zero-based.", nameof(array));

Type guard

static bool IsZeroBased(Array a) => a.GetLowerBound(0) == 0;

Prevention

When it happens

Trigger: Passing an array created with Array.CreateInstance(typeof(T), new[]{length}, new[]{1}) (non-zero lower bound) to CopyTo.

Common situations: Legacy interop or COM-style code that produces non-zero-based arrays; rare VB6-style array interop.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/25ae9ecee7faf3c6. Report an issue: GitHub.