{"record":{"id":"ecd6354bcfc88d8d","repo":"stride3d/stride","slug":"destination-array-cannot-be-null","errorCode":null,"errorMessage":"Destination array cannot be null.","messagePattern":"Destination array cannot be null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/Collections/Dequeue.cs","lineNumber":357,"sourceCode":"    }\n\n    object System.Collections.IList.this[int index]\n    {\n        get\n        {\n            return this[index];\n        }\n\n        set\n        {\n            this[index] = (T)value;\n        }\n    }\n\n    void System.Collections.ICollection.CopyTo(Array array, int index)\n    {\n        if (array == null)\n            throw new ArgumentNullException(nameof(array), \"Destination array cannot be null.\");\n        CheckRangeArguments(array.Length, index, Count);\n\n        for (int i = 0; i != Count; ++i)\n        {\n            try\n            {\n                array.SetValue(this[i], index + i);\n            }\n            catch (InvalidCastException ex)\n            {\n                throw new ArgumentException(\"Destination array is of incorrect type.\", ex);\n            }\n        }\n    }\n\n    bool System.Collections.ICollection.IsSynchronized => false;\n\n    object System.Collections.ICollection.SyncRoot => this;","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/Collections/Dequeue.cs#L339-L375","documentation":"Deque<T>'s non-generic System.Collections.ICollection.CopyTo(Array array, int index) is used when the deque is accessed through the legacy non-generic collection interface (e.g. reflection-based serializers, legacy collection interop). It throws ArgumentNullException('Destination array cannot be null.') when the supplied Array is null, before the range check and element copying.","triggerScenarios":"((ICollection)deque).CopyTo(null, 0); calling CopyTo on an ICollection-typed variable with a null destination; frameworks invoking the non-generic interface member with an uninitialized buffer.","commonSituations":"Legacy collection APIs (e.g. code written against ArrayList-era patterns); serializers that use the non-generic ICollection contract; cast-through-object code paths that lose type information.","solutions":["Ensure a non-null Array is allocated before calling the non-generic CopyTo.","Prefer the generic ICollection<T>.CopyTo (or ToArray) which is compile-time type-safe.","Null-check the destination before dispatching through the ICollection interface."],"exampleFix":"// before\n((ICollection)deque).CopyTo(destination, 0); // destination may be null\n\n// after\nif (destination != null)\n    ((ICollection)deque).CopyTo(destination, 0);","handlingStrategy":"type-guard","validationCode":"if (array == null)\n    throw new ArgumentException(\"Destination array must be allocated before CopyTo\");\n((ICollection)deque).CopyTo(array, index);","typeGuard":"static bool CanCopyTo(Array? array, int index, int count) =>\n    array is not null && index >= 0 && count <= array.Length - index;","tryCatchPattern":"try\n{\n    ((ICollection)deque).CopyTo(array, index);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"array\")\n{\n    logger.Error(\"Non-generic CopyTo called with a null destination array\");\n}","preventionTips":["Prefer the generic ICollection<T>.CopyTo over the non-generic path.","Null-check the destination before dispatching through the ICollection interface.","Ensure serialization/interop frameworks supply initialized buffers."],"tags":["csharp","stride-core","collections","null-reference"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}