{"record":{"id":"e5c4c53a8e246e9d","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-disposable2-e5c4c5","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'disposable2')","messagePattern":"Value cannot be null\\. \\(Parameter 'disposable2'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Disposables/StableCompositeDisposable.cs","lineNumber":31,"sourceCode":"#pragma warning disable CA1063 // (Overridable IDisposable.) This analyzer wants us to make breaking changes to its public API, which we can't do.\n    public abstract class StableCompositeDisposable : ICancelable\n    {\n        /// <summary>\n        /// Creates a new group containing two disposable resources that are disposed together.\n        /// </summary>\n        /// <param name=\"disposable1\">The first disposable resource to add to the group.</param>\n        /// <param name=\"disposable2\">The second disposable resource to add to the group.</param>\n        /// <returns>Group of disposable resources that are disposed together.</returns>\n        public static ICancelable Create(IDisposable disposable1, IDisposable disposable2)\n        {\n            if (disposable1 == null)\n            {\n                throw new ArgumentNullException(nameof(disposable1));\n            }\n\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);","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Disposables/StableCompositeDisposable.cs#L13-L49","documentation":"StableCompositeDisposable.Create(IDisposable, IDisposable) throws ArgumentNullException when the second argument is null. Each of the two-argument overload's parameters is validated independently, so this fires only when disposable2 is null.","triggerScenarios":"Calling StableCompositeDisposable.Create(d1, null) — second argument null, e.g. the second resource acquisition returned null.","commonSituations":"Optional second subscription (e.g. a timer or background resource that was never created), or refactoring that made one of the two sources nullable.","solutions":["Ensure the second disposable is created before composing.","Substitute Disposable.Empty for the null element.","Null-check and compose only the non-null disposables."],"exampleFix":"// before\nvar composite = StableCompositeDisposable.Create(first, second); // second is null\n// after\nvar composite = StableCompositeDisposable.Create(first, second ?? Disposable.Empty);","handlingStrategy":"validation","validationCode":"if (second is null) second = Disposable.Empty;\nvar composite = StableCompositeDisposable.Create(first, second);","typeGuard":"static bool IsValidPair(IDisposable a, IDisposable b) => a is not null && b is not null;","tryCatchPattern":"try { var c = StableCompositeDisposable.Create(first, second); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"disposable2\") { /* compose remaining or use Empty */ }","preventionTips":["Default optional second resources to Disposable.Empty.","Check nullable annotations on the variables feeding the call.","Cover 'missing resource' branches in unit tests."],"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"}