{"record":{"id":"0b066f15b6a5b2a8","repo":"AvaloniaUI/Avalonia","slug":"destination-too-short","errorCode":null,"errorMessage":"Destination too short.","messagePattern":"Destination too short\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Collections/Pooled/ThrowHelper.cs","lineNumber":70,"sourceCode":"            throw new ArrayTypeMismatchException();\n        }\n\n        [DoesNotReturn]\n        internal static void ThrowIndexOutOfRangeException()\n        {\n            throw new IndexOutOfRangeException();\n        }\n\n        [DoesNotReturn]\n        internal static void ThrowArgumentOutOfRangeException()\n        {\n            throw new ArgumentOutOfRangeException();\n        }\n\n        [DoesNotReturn]\n        internal static void ThrowArgumentException_DestinationTooShort()\n        {\n            throw new ArgumentException(\"Destination too short.\");\n        }\n\n        [DoesNotReturn]\n        internal static void ThrowArgumentException_OverlapAlignmentMismatch()\n        {\n            throw new ArgumentException(\"Overlap alignment mismatch.\");\n        }\n\n        [DoesNotReturn]\n        internal static void ThrowArgumentOutOfRange_IndexException()\n        {\n            throw GetArgumentOutOfRangeException(ExceptionArgument.index,\n                                                    ExceptionResource.ArgumentOutOfRange_Index);\n        }\n\n        [DoesNotReturn]\n        internal static void ThrowIndexArgumentOutOfRange_NeedNonNegNumException()\n        {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Collections/Pooled/ThrowHelper.cs#L52-L88","documentation":"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.","triggerScenarios":"Calling `stack.CopyTo(span)` with a span shorter than stack.Count; copying into a stackalloc or rented buffer sized to the wrong value.","commonSituations":"Under-sizing a destination buffer (using Capacity or an unrelated count); slicing a span too short; renting from a pool by an estimated size.","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."],"exampleFix":"// before\nSpan<T> buf = new T[8];\nstack.CopyTo(buf); // throws if stack.Count > 8\n\n// after\nSpan<T> buf = new T[stack.Count];\nstack.CopyTo(buf);","handlingStrategy":"validation","validationCode":"if (span.Length < stack.Count)\n    span = new T[stack.Count];\nstack.CopyTo(span);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Size the destination span to stack.Count.","Use stack.ToArray() when a fresh array is acceptable.","Re-check Count immediately before allocating the buffer."],"tags":["csharp","pooled","stack","span","copy"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}