{"record":{"id":"69ae2a40294f4407","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-functionasync","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'functionAsync')","messagePattern":"Value cannot be null\\. \\(Parameter 'functionAsync'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs","lineNumber":1043,"sourceCode":"\n        /// <summary>\n        /// Invokes the asynchronous function, surfacing the result through an observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type of the result returned by the asynchronous function.</typeparam>\n        /// <param name=\"functionAsync\">Asynchronous function to run.</param>\n        /// <returns>An observable sequence exposing the function's result value, or an exception.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"functionAsync\"/> is null.</exception>\n        /// <remarks>\n        /// <list type=\"bullet\">\n        /// <item><description>The function is started immediately, not during the subscription of the resulting sequence.</description></item>\n        /// <item><description>Multiple subscriptions to the resulting sequence can observe the function's result.</description></item>\n        /// </list>\n        /// </remarks>\n        public static IObservable<TResult> StartAsync<TResult>(Func<Task<TResult>> functionAsync)\n        {\n            if (functionAsync == null)\n            {\n                throw new ArgumentNullException(nameof(functionAsync));\n            }\n\n            return s_impl.StartAsync(functionAsync);\n        }\n\n        /// <summary>\n        /// Invokes the asynchronous function, surfacing the result through an observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type of the result returned by the asynchronous function.</typeparam>\n        /// <param name=\"functionAsync\">Asynchronous function to run.</param>\n        /// <param name=\"scheduler\">Scheduler on which to notify observers.</param>\n        /// <returns>An observable sequence exposing the function's result value, or an exception.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"functionAsync\"/> is null or <paramref name=\"scheduler\"/> is null.</exception>\n        /// <remarks>\n        /// <list type=\"bullet\">\n        /// <item><description>The function is started immediately, not during the subscription of the resulting sequence.</description></item>\n        /// <item><description>Multiple subscriptions to the resulting sequence can observe the function's result.</description></item>\n        /// </list>","sourceCodeStart":1025,"sourceCodeEnd":1061,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs#L1025-L1061","documentation":"Observable.StartAsync<TResult>(Func<Task<TResult>> functionAsync) throws ArgumentNullException when the async factory delegate is null. The delegate is the core of the operation — it produces the Task whose result the observable emits — so the library fails fast rather than producing an observable that errors only on subscribe.","triggerScenarios":"Calling Observable.StartAsync with a null Func<Task<TResult>>, e.g. an unassigned async lambda variable or a null returned from a strategy/registry lookup of async work.","commonSituations":"Conditional assignment of an async delegate, storing Func<Task<T>> in a nullable field populated asynchronously, or reflection-based delegate construction that silently failed.","solutions":["Ensure the Func<Task<TResult>> delegate is assigned before calling StartAsync","If the delegate is looked up, validate the lookup result and throw a clearer error","Prefer passing the async method group directly (e.g. StartAsync(DoWorkAsync)) instead of a variable"],"exampleFix":"// before\nFunc<Task<int>> f = registry.GetHandler(name); // may be null\nObservable.StartAsync(f);\n// after\nFunc<Task<int>> f = registry.GetHandler(name) ?? throw new InvalidOperationException($\"no handler for {name}\");\nObservable.StartAsync(f);","handlingStrategy":"validation","validationCode":"if (functionAsync == null) throw new ArgumentNullException(nameof(functionAsync));\nObservable.StartAsync(functionAsync);","typeGuard":"bool IsValidAsync(Func<Task<TResult>> f) => f is not null;","tryCatchPattern":"try { Observable.StartAsync(functionAsync); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"functionAsync\") { log.LogError(\"StartAsync requires a non-null async delegate\"); throw; }","preventionTips":["Pass async method groups directly instead of stored nullable delegates","Fail fast where the delegate is resolved, not inside the Rx call","Avoid conditionally assigned Func<Task<T>> variables"],"tags":["csharp","rx","async","null-argument"],"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"}