{"record":{"id":"436d0bd69e23a8e5","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-disposable1","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'disposable1')","messagePattern":"Value cannot be null\\. \\(Parameter 'disposable1'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Disposables/StableCompositeAsyncDisposable.cs","lineNumber":16,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Collections.Generic;\nusing System.Threading;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Disposables\n{\n    public abstract class StableCompositeAsyncDisposable : IAsyncDisposable\n    {\n        public static StableCompositeAsyncDisposable Create(IAsyncDisposable disposable1, IAsyncDisposable disposable2)\n        {\n            if (disposable1 == null)\n                throw new ArgumentNullException(nameof(disposable1));\n            if (disposable2 == null)\n                throw new ArgumentNullException(nameof(disposable2));\n\n            return new Binary(disposable1, disposable2);\n        }\n\n        public static StableCompositeAsyncDisposable Create(params IAsyncDisposable[] disposables)\n        {\n            if (disposables == null)\n                throw new ArgumentNullException(nameof(disposables));\n\n            return new NAry(disposables);\n        }\n\n        public static StableCompositeAsyncDisposable Create(IEnumerable<IAsyncDisposable> disposables)\n        {\n            if (disposables == null)\n                throw new ArgumentNullException(nameof(disposables));","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Disposables/StableCompositeAsyncDisposable.cs#L1-L34","documentation":"StableCompositeAsyncDisposable.Create(disposable1, disposable2) validates both disposables before building a Binary composite. This library throws ArgumentNullException for null arguments to fail fast instead of throwing later during DisposeAsync. The first parameter was null.","triggerScenarios":"Calling StableCompositeAsyncDisposable.Create(null, someDisposable) with a null first IAsyncDisposable, typically because an upstream factory or field returned null.","commonSituations":"Wiring up two resources where one failed to initialize (e.g. a cancelled connection returned null); refactors that change disposal ownership leaving one field unset; conditional resource creation paths that skip assignment.","solutions":["Pass a non-null IAsyncDisposable as the first argument (e.g. NoopAsyncDisposable or a real resource).","Check the code producing disposable1 for null-returning factory calls and handle that null there.","If one side may be absent, guard with a conditional before composing, or filter nulls from your disposal list and use the params Create overload."],"exampleFix":"// before\nvar composite = StableCompositeAsyncDisposable.Create(GetClient(), subscription);\n// after\nvar client = GetClient() ?? throw new InvalidOperationException(\"client not initialized\");\nvar composite = StableCompositeAsyncDisposable.Create(client, subscription);","handlingStrategy":"validation","validationCode":"if (disposable1 is null) throw new ArgumentNullException(nameof(disposable1));\nvar composite = StableCompositeAsyncDisposable.Create(disposable1, disposable2);","typeGuard":"static bool IsDisposable(IAsyncDisposable? d) => d is not null;","tryCatchPattern":"try { var c = StableCompositeAsyncDisposable.Create(d1, d2); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"disposable1\")\n{ log.LogWarning(\"disposable1 was null\"); }","preventionTips":["Never let factory methods return null disposables; return a null-object disposable instead.","Use nullable reference types (IAsyncDisposable?) and enable CS8604 warnings.","Filter nulls before composing disposables."],"tags":["argument-null","disposables","async-rx"],"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"}