{"record":{"id":"d3b3127c20da5e38","repo":"AvaloniaUI/Avalonia","slug":"array","errorCode":null,"errorMessage":"array","messagePattern":"array","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Collections/AvaloniaList.cs","lineNumber":661,"sourceCode":"\n        /// <inheritdoc/>\n        void IList.Remove(object? value)\n        {\n            Remove((T)value!);\n        }\n\n        /// <inheritdoc/>\n        void IList.RemoveAt(int index)\n        {\n            RemoveAt(index);\n        }\n\n        /// <inheritdoc/>\n        void ICollection.CopyTo(Array array, int index)\n        {\n            if (array == null)\n            {\n                throw new ArgumentNullException(nameof(array));\n            }\n\n            if (array.Rank != 1)\n            {\n                throw new ArgumentException(\"Multi-dimensional arrays are not supported.\");\n            }\n\n            if (array.GetLowerBound(0) != 0)\n            {\n                throw new ArgumentException(\"Non-zero lower bounds are not supported.\");\n            }\n\n            if (index < 0)\n            {\n                throw new ArgumentException(\"Invalid index.\");\n            }\n\n            if (array.Length - index < Count)","sourceCodeStart":643,"sourceCodeEnd":679,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Collections/AvaloniaList.cs#L643-L679","documentation":"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.","triggerScenarios":"Calling ((ICollection)list).CopyTo(null, index) or ((Array)null, ...) via the non-generic ICollection interface; frameworks/collection adapters passing a null destination array.","commonSituations":"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.","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."],"exampleFix":"// before\n((ICollection)list).CopyTo(null, 0);\n\n// after\nvar arr = new T[list.Count];\n((ICollection)list).CopyTo(arr, 0);","handlingStrategy":"validation","validationCode":"_ = array ?? throw new ArgumentNullException(nameof(array));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Allocate the destination array before calling CopyTo.","Prefer the strongly-typed CopyTo(T[], int) overload.","Null-check array at the call boundary."],"tags":["avalonia","collections","list","null-argument","copyto"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}