{"record":{"id":"157a64d54b0a62b8","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-disposable1-157a64","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'disposable1')","messagePattern":"Value cannot be null\\. \\(Parameter 'disposable1'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Disposables/StableCompositeDisposable.cs","lineNumber":26,"sourceCode":"namespace System.Reactive.Disposables\n{\n    /// <summary>\n    /// Represents a group of disposable resources that are disposed together.\n    /// </summary>\n#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)","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Disposables/StableCompositeDisposable.cs#L8-L44","documentation":"StableCompositeDisposable.Create(IDisposable, IDisposable) validates both arguments and throws ArgumentNullException when the first is null. A composite must be built only from real disposables; a null element would break disposal behavior, so it is rejected up front.","triggerScenarios":"Calling StableCompositeDisposable.Create(null, d2) — first argument null, e.g. a first subscription/resource that was null.","commonSituations":"Combining two resources where one acquisition returned null, event-driven code where one of the resources is optional, or LINQ/conditional setup leaving a variable unassigned.","solutions":["Ensure the first disposable is created before composing.","Substitute Disposable.Empty for the null element so the composite remains valid.","Null-check and fall back to composing only the non-null disposables."],"exampleFix":"// before\nvar composite = StableCompositeDisposable.Create(first, second); // first is null\n// after\nvar composite = StableCompositeDisposable.Create(first ?? Disposable.Empty, second);","handlingStrategy":"validation","validationCode":"if (first is null) first = 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 == \"disposable1\") { /* compose remaining or use Empty */ }","preventionTips":["Coalesce every optional disposable with Disposable.Empty before composing.","Enable nullable reference types so null disposables surface at compile time.","Keep resource acquisition methods non-null-returning."],"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"}