{"record":{"id":"2ff225452d737b9c","repo":"AvaloniaUI/Avalonia","slug":"value-cannot-be-null-parameter-array","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'array')","messagePattern":"Value cannot be null\\. \\(Parameter 'array'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Reactive/CompositeDisposable.cs","lineNumber":296,"sourceCode":"                return false;\n            }\n\n            return _disposables.Contains(item);\n        }\n    }\n\n    /// <summary>\n    /// Copies the disposables contained in the <see cref=\"CompositeDisposable\"/> to an array, starting at a particular array index.\n    /// </summary>\n    /// <param name=\"array\">Array to copy the contained disposables to.</param>\n    /// <param name=\"arrayIndex\">Target index at which to copy the first disposable of the group.</param>\n    /// <exception cref=\"ArgumentNullException\"><paramref name=\"array\"/> is <c>null</c>.</exception>\n    /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"arrayIndex\"/> is less than zero. -or - <paramref name=\"arrayIndex\"/> is larger than or equal to the array length.</exception>\n    public void CopyTo(IDisposable[] array, int arrayIndex)\n    {\n        if (array == null)\n        {\n            throw new ArgumentNullException(nameof(array));\n        }\n\n        if (arrayIndex < 0 || arrayIndex >= array.Length)\n        {\n            throw new ArgumentOutOfRangeException(nameof(arrayIndex));\n        }\n\n        lock (_gate)\n        {\n            // disposed composites are always empty\n            if (_disposed)\n            {\n                return;\n            }\n\n            if (arrayIndex + _count > array.Length)\n            {\n                // there is not enough space beyond arrayIndex ","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Reactive/CompositeDisposable.cs#L278-L314","documentation":"CompositeDisposable.CopyTo(array, arrayIndex) copies contained disposables into a target array and throws ArgumentNullException(nameof(array)) when array is null, before any index check. Standard ICollection<T> contract.","triggerScenarios":"Calling composite.CopyTo(null, 0) or passing a null IDisposable[] variable.","commonSituations":"Allocating the destination array conditionally and leaving it null on some path, then unconditionally calling CopyTo.","solutions":["Allocate the target array before CopyTo: var arr = new IDisposable[composite.Count];.","Null-check and branch if the array is optional.","Use composite.ToArray()-equivalent helpers where the framework provides them."],"exampleFix":"// before\nIDisposable[] arr = null;\ncomposite.CopyTo(arr, 0);\n\n// after\nvar arr = new IDisposable[composite.Count];\ncomposite.CopyTo(arr, 0);","handlingStrategy":"validation","validationCode":"var arr = new IDisposable[composite.Count];\ncomposite.CopyTo(arr, 0);","typeGuard":"bool NotNull(IDisposable[]? a) => a is not null;","tryCatchPattern":null,"preventionTips":["Always allocate the destination array before CopyTo.","Branch if the array is optional.","Use ToArray()-style helpers when available."],"tags":["avalonia","reactive","disposables","argumentnull","copyto"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}