{"record":{"id":"c3a6476cbb5ab026","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-disposables-c3a647","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'disposables')","messagePattern":"Value cannot be null\\. \\(Parameter 'disposables'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Disposables/CompositeDisposable.cs","lineNumber":68,"sourceCode":"            if (capacity < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(capacity));\n            }\n\n            _disposables = new List<IDisposable?>(capacity);\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"CompositeDisposable\"/> class from a group of disposables.\n        /// </summary>\n        /// <param name=\"disposables\">Disposables that will be disposed together.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"disposables\"/> is <c>null</c>.</exception>\n        /// <exception cref=\"ArgumentException\">Any of the disposables in the <paramref name=\"disposables\"/> collection is <c>null</c>.</exception>\n        public CompositeDisposable(params IDisposable[] disposables)\n        {\n            if (disposables == null)\n            {\n                throw new ArgumentNullException(nameof(disposables));\n            }\n\n            (_disposables, _) = ToListOrDictionary(disposables);\n\n            // _count can be read by other threads and thus should be properly visible\n            // also releases the _disposables contents so it becomes thread-safe\n            Volatile.Write(ref _count, disposables.Length);\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"CompositeDisposable\"/> class from a group of disposables.\n        /// </summary>\n        /// <param name=\"disposables\">Disposables that will be disposed together.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"disposables\"/> is <c>null</c>.</exception>\n        /// <exception cref=\"ArgumentException\">Any of the disposables in the <paramref name=\"disposables\"/> collection is <c>null</c>.</exception>\n        public CompositeDisposable(IEnumerable<IDisposable> disposables)\n        {\n            if (disposables == null)","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Disposables/CompositeDisposable.cs#L50-L86","documentation":"CompositeDisposable's params IDisposable[] constructor first checks the whole array for null before processing its items. Passing a null array gives the composite nothing to hold, so ArgumentNullException with parameter name 'disposables' is thrown.","triggerScenarios":"new CompositeDisposable(null) or new CompositeDisposable(someNullArray) — commonly when the array is the result of a lookup/transform that returned null, or when calling with a single null argument that binds to the params overload.","commonSituations":"Passing an uninitialized IDisposable[] field; calling CompositeDisposable(MaybeNullDisposable()) intending the single-item overload but hitting the params overload with null; LINQ/ToArray results assumed non-null.","solutions":["Ensure the array is non-null before constructing: disposableArray ??= Array.Empty<IDisposable>()","If you may pass zero items, prefer new CompositeDisposable() or an empty array","If passing a possibly-null single disposable, guard it first or filter it out"],"exampleFix":"// before\nvar cd = new CompositeDisposable(GetDisposables()); // may return null\n// after\nvar items = GetDisposables() ?? Array.Empty<IDisposable>();\nvar cd = new CompositeDisposable(items);","handlingStrategy":"type-guard","validationCode":"if (disposables == null) disposables = Array.Empty<IDisposable>();\nvar cd = new CompositeDisposable(disposables);","typeGuard":"bool IsUsableArray(IDisposable[]? a) => a is { Length: > 0 };","tryCatchPattern":"try { return new CompositeDisposable(arr); }\ncatch (ArgumentNullException) { return new CompositeDisposable(); }","preventionTips":["Coalesce null arrays to Array.Empty<IDisposable>()","Never return null arrays from provider methods","Watch out for a lone null argument binding to the params overload"],"tags":["rx","disposable","null-argument"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}