{"record":{"id":"3ca9898fea351bd2","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-disposables-3ca989","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'disposables')","messagePattern":"Value cannot be null\\. \\(Parameter 'disposables'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Disposables/StableCompositeDisposable.cs","lineNumber":46,"sourceCode":"\n            if (disposable2 == null)\n            {\n                throw new ArgumentNullException(nameof(disposable2));\n            }\n\n            return new Binary(disposable1, disposable2);\n        }\n\n        /// <summary>\n        /// Creates a new group of disposable resources that are disposed together.\n        /// </summary>\n        /// <param name=\"disposables\">Disposable resources to add to the group.</param>\n        /// <returns>Group of disposable resources that are disposed together.</returns>\n        public static ICancelable Create(params IDisposable[] disposables)\n        {\n            if (disposables == null)\n            {\n                throw new ArgumentNullException(nameof(disposables));\n            }\n\n            return new NAryArray(disposables);\n        }\n\n        /// <summary>\n        /// Creates a group of disposable resources that are disposed together\n        /// and without copying or checking for nulls inside the group.\n        /// </summary>\n        /// <param name=\"disposables\">The array of disposables that is trusted\n        /// to not contain nulls and gives no need to defensively copy it.</param>\n        /// <returns>Group of disposable resources that are disposed together.</returns>\n        internal static ICancelable CreateTrusted(params IDisposable[] disposables)\n        {\n            return new NAryTrustedArray(disposables);\n        }\n\n        /// <summary>","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Disposables/StableCompositeDisposable.cs#L28-L64","documentation":"The params-array overload StableCompositeDisposable.Create(params IDisposable[]) throws ArgumentNullException when the array itself is null. The array object (not its elements) must be non-null for the NAryArray composite to be built.","triggerScenarios":"Calling StableCompositeDisposable.Create(null) with a null IDisposable[] — typically passing a null array variable rather than relying on params expansion, or forwarding a null array from another API.","commonSituations":"Aggregating disposables collected in a list that was converted with ToArray() on a null source, or forwarding an optional params argument from a wrapper method.","solutions":["Ensure the array is non-null before forwarding it to Create.","Pass an empty array instead of null when there are no disposables.","Filter the source collection and build the array defensively before calling Create."],"exampleFix":"// before\nvar composite = StableCompositeDisposable.Create(collected); // collected is null\n// after\nvar composite = StableCompositeDisposable.Create(collected ?? Array.Empty<IDisposable>());","handlingStrategy":"validation","validationCode":"if (disposables is null) disposables = Array.Empty<IDisposable>();\nvar composite = StableCompositeDisposable.Create(disposables);","typeGuard":"static bool HasArray(IDisposable[] items) => items is not null;","tryCatchPattern":"try { var c = StableCompositeDisposable.Create(disposables); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"disposables\") { /* use empty composite */ }","preventionTips":["Never forward possibly-null arrays; use ?? Array.Empty<IDisposable>().","Prefer the IEnumerable overload with a null-coalesced LINQ source.","Ensure collection-producing methods return empty, never null."],"tags":["null-argument","disposables","composite-disposable","system-reactive"],"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"}