{"record":{"id":"05fb2e24cab7b4cc","repo":"dotnet/reactive","slug":"nameof-subscribeasync","errorCode":null,"errorMessage":"nameof(subscribeAsync)","messagePattern":"nameof\\(subscribeAsync\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs","lineNumber":77,"sourceCode":"        #endregion\n\n        #region + CreateAsync +\n\n        /// <summary>\n        /// Creates an observable sequence from a specified cancellable asynchronous Subscribe method.\n        /// The CancellationToken passed to the asynchronous Subscribe method is tied to the returned disposable subscription, allowing best-effort cancellation.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type of the elements in the produced sequence.</typeparam>\n        /// <param name=\"subscribeAsync\">Asynchronous method used to produce elements.</param>\n        /// <returns>The observable sequence surfacing the elements produced by the asynchronous method.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"subscribeAsync\"/> is null.</exception>\n        /// <remarks>This operator is especially useful in conjunction with the asynchronous programming features introduced in C# 5.0 and Visual Basic 11.</remarks>\n        /// <remarks>When a subscription to the resulting sequence is disposed, the CancellationToken that was fed to the asynchronous subscribe function will be signaled.</remarks>\n        public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, CancellationToken, Task> subscribeAsync)\n        {\n            if (subscribeAsync == null)\n            {\n                throw new ArgumentNullException(nameof(subscribeAsync));\n            }\n\n            return s_impl.Create(subscribeAsync);\n        }\n\n        /// <summary>\n        /// Creates an observable sequence from a specified asynchronous Subscribe method.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type of the elements in the produced sequence.</typeparam>\n        /// <param name=\"subscribeAsync\">Asynchronous method used to produce elements.</param>\n        /// <returns>The observable sequence surfacing the elements produced by the asynchronous method.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"subscribeAsync\"/> is null.</exception>\n        /// <remarks>This operator is especially useful in conjunction with the asynchronous programming features introduced in C# 5.0 and Visual Basic 11.</remarks>\n        public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, Task> subscribeAsync)\n        {\n            if (subscribeAsync == null)\n            {\n                throw new ArgumentNullException(nameof(subscribeAsync));","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs#L59-L95","documentation":"Observable.Create<TResult> with an async subscribe delegate (Func<IObserver<TResult>, CancellationToken, Task>) throws ArgumentNullException when subscribeAsync is null. This overload supports async/await-based observables, wiring a CancellationToken that fires on disposal. Rx validates the delegate immediately at Create.","triggerScenarios":"Calling Observable.Create<TResult>(subscribeAsync) with a null Func<IObserver<TResult>, CancellationToken, Task>, e.g. an unassigned async method reference or a factory returning null.","commonSituations":"Async observable construction where the async lambda was refactored into a method that no longer exists, or DI/config-driven delegate selection yielding null.","solutions":["Pass a valid async lambda: async (o, ct) => { ... }","Fix the delegate source that returned null","Guard the delegate for null before Create"],"exampleFix":"// before\nvar obs = Observable.Create<int>(subscribeAsync); // subscribeAsync is null\n// after\nvar obs = Observable.Create<int>(async (o, ct) =>\n{\n    await Task.Yield();\n    o.OnNext(1);\n    o.OnCompleted();\n});","handlingStrategy":"validation","validationCode":"if (subscribeAsync == null) throw new ArgumentNullException(nameof(subscribeAsync));\nvar obs = Observable.Create<T>(subscribeAsync);","typeGuard":"bool IsValid<T>(Func<IObserver<T>, CancellationToken, Task> f) => f is not null;","tryCatchPattern":"try { var obs = Observable.Create<T>(subscribeAsync); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"subscribeAsync\") { /* handle null delegate */ }","preventionTips":["Pass async lambdas directly to Create rather than storing them in nullable fields","Keep async subscribe methods non-static-safe: verify receiver instance is non-null before method-group reference","Compile with nullable reference types so unassigned delegates are flagged"],"tags":["dotnet","rx","null-argument","async"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}