dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'disposables')
Error message
Value cannot be null. (Parameter 'disposables')
What it means
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.
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.
Example fix
// before var composite = StableCompositeDisposable.Create(collected); // collected is null // after var composite = StableCompositeDisposable.Create(collected ?? Array.Empty<IDisposable>());
Defensive patterns
Strategy: validation
Validate before calling
if (disposables is null) disposables = Array.Empty<IDisposable>(); var composite = StableCompositeDisposable.Create(disposables);
Type guard
static bool HasArray(IDisposable[] items) => items is not null;
Try / catch
try { var c = StableCompositeDisposable.Create(disposables); }
catch (ArgumentNullException ex) when (ex.ParamName == "disposables") { /* use empty composite */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Value cannot be null. (Parameter 'disposable1')
- Value cannot be null. (Parameter 'disposable2')
- Value cannot be null. (Parameter 'disposable')
- Value cannot be null. (Parameter 'disposable')
- RefCountDisposable
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/3ca9898fea351bd2.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Disposables/StableCompositeDisposable.cs:46
if (disposable2 == null)
{
throw new ArgumentNullException(nameof(disposable2));
}
return new Binary(disposable1, disposable2);
}
/// <summary>
/// Creates a new group of disposable resources that are disposed together.
/// </summary>
/// <param name="disposables">Disposable resources to add to the group.</param>
/// <returns>Group of disposable resources that are disposed together.</returns>
public static ICancelable Create(params IDisposable[] disposables)
{
if (disposables == null)
{
throw new ArgumentNullException(nameof(disposables));
}
return new NAryArray(disposables);
}
/// <summary>
/// Creates a group of disposable resources that are disposed together
/// and without copying or checking for nulls inside the group.
/// </summary>
/// <param name="disposables">The array of disposables that is trusted
/// to not contain nulls and gives no need to defensively copy it.</param>
/// <returns>Group of disposable resources that are disposed together.</returns>
internal static ICancelable CreateTrusted(params IDisposable[] disposables)
{
return new NAryTrustedArray(disposables);
}
/// <summary>View on GitHub (pinned to 94b5d5ab91)