dotnet/reactive · error · ArgumentNullException

ArgumentNullException(nameof(observableFactory))

Error message

ArgumentNullException(nameof(observableFactory))

What it means

Using validates observableFactory, which builds the observable from the acquired resource; null is rejected because the sequence to subscribe would be undefined. Fix: pass a non-null Func<TResource, IAsyncObservable<TResult>>.

Solutions

  1. Pass a non-null Func<TResource, IAsyncObservable<TResult>>.
  2. Ensure the lambda is defined for the generic TResource in use.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/Using.cs:18 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15). Data as JSON: /api/errors/6ef27dec6f9035af. Report an issue: GitHub.

Appendix: source

Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/Using.cs:18

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT License.
// See the LICENSE file in the project root for more information. 

using System.Reactive.Disposables;
using System.Threading.Tasks;

namespace System.Reactive.Linq
{
    public partial class AsyncObservable
    {
        public static IAsyncObservable<TResult> Using<TResult, TResource>(Func<TResource> resourceFactory, Func<TResource, IAsyncObservable<TResult>> observableFactory)
            where TResource : IDisposable
        {
            if (resourceFactory == null)
                throw new ArgumentNullException(nameof(resourceFactory));
            if (observableFactory == null)
                throw new ArgumentNullException(nameof(observableFactory));

            return Create<TResult>(async observer =>
            {
                TResource resource;
                try
                {
                    resource = resourceFactory();
                }
                catch (Exception ex)
                {
                    await observer.OnErrorAsync(ex).ConfigureAwait(false);
                    return AsyncDisposable.Nop;
                }

                IAsyncObservable<TResult> observable;
                try
                {
                    observable = observableFactory(resource);

View on GitHub (pinned to 94b5d5ab91)