AvaloniaUI/Avalonia · error · ArgumentException
Destination too short.
Error message
Destination too short.
What it means
Centralized ThrowHelper.ThrowArgumentException_DestinationTooShort throws ArgumentException "Destination too short." It is invoked from PooledStack<T>.CopyTo(Span<T>) when `span.Length < _size`, i.e. the destination span cannot hold the whole stack. It is the PooledStack analogue of PooledList's span-too-short check, hoisted into ThrowHelper to reduce IL/code size.
Source
Thrown at src/Avalonia.Base/Collections/Pooled/ThrowHelper.cs:70
throw new ArrayTypeMismatchException();
}
[DoesNotReturn]
internal static void ThrowIndexOutOfRangeException()
{
throw new IndexOutOfRangeException();
}
[DoesNotReturn]
internal static void ThrowArgumentOutOfRangeException()
{
throw new ArgumentOutOfRangeException();
}
[DoesNotReturn]
internal static void ThrowArgumentException_DestinationTooShort()
{
throw new ArgumentException("Destination too short.");
}
[DoesNotReturn]
internal static void ThrowArgumentException_OverlapAlignmentMismatch()
{
throw new ArgumentException("Overlap alignment mismatch.");
}
[DoesNotReturn]
internal static void ThrowArgumentOutOfRange_IndexException()
{
throw GetArgumentOutOfRangeException(ExceptionArgument.index,
ExceptionResource.ArgumentOutOfRange_Index);
}
[DoesNotReturn]
internal static void ThrowIndexArgumentOutOfRange_NeedNonNegNumException()
{View on GitHub (pinned to 11c5427268)
Solutions
- Allocate the span to Count: `Span<T> buf = new T[stack.Count]; stack.CopyTo(buf);`.
- Read elements directly via stack.ToArray() if a materialized array is acceptable.
- Validate `span.Length >= stack.Count` before copying.
Example fix
// before Span<T> buf = new T[8]; stack.CopyTo(buf); // throws if stack.Count > 8 // after Span<T> buf = new T[stack.Count]; stack.CopyTo(buf);
Defensive patterns
Strategy: validation
Validate before calling
if (span.Length < stack.Count)
span = new T[stack.Count];
stack.CopyTo(span); Prevention
- Size the destination span to stack.Count.
- Use stack.ToArray() when a fresh array is acceptable.
- Re-check Count immediately before allocating the buffer.
When it happens
Trigger: Calling `stack.CopyTo(span)` with a span shorter than stack.Count; copying into a stackalloc or rented buffer sized to the wrong value.
Common situations: Under-sizing a destination buffer (using Capacity or an unrelated count); slicing a span too short; renting from a pool by an estimated size.
Related errors
- Destination span is shorter than the list to be copied.
- array
- Stack was empty.
- Collection was modified during enumeration.
- Enumeration was not started. | Enumeration has ended.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/0b066f15b6a5b2a8.
Report an issue: GitHub.