{"record":{"id":"171c7694f01e911c","repo":"dotnet/reactive","slug":"argument-cannot-be-null-parameter-name-actionasync","errorCode":null,"errorMessage":"Argument cannot be null (Parameter name: actionAsync)","messagePattern":"Argument cannot be null \\(Parameter name: actionAsync\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/FromAsync.cs","lineNumber":52,"sourceCode":"                throw new ArgumentNullException(nameof(functionAsync));\n\n            return Defer(() => StartAsync(functionAsync));\n        }\n\n        public static IAsyncObservable<TResult> FromAsync<TResult>(Func<CancellationToken, ValueTask<TResult>> functionAsync, IAsyncScheduler scheduler)\n        {\n            if (functionAsync == null)\n                throw new ArgumentNullException(nameof(functionAsync));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Defer(() => StartAsync(functionAsync, scheduler));\n        }\n\n        public static IAsyncObservable<Unit> FromAsync(Func<Task> actionAsync)\n        {\n            if (actionAsync == null)\n                throw new ArgumentNullException(nameof(actionAsync));\n\n            return Defer(() => StartAsync(actionAsync));\n        }\n\n        public static IAsyncObservable<Unit> FromAsync(Func<Task> actionAsync, IAsyncScheduler scheduler)\n        {\n            if (actionAsync == null)\n                throw new ArgumentNullException(nameof(actionAsync));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Defer(() => StartAsync(actionAsync, scheduler));\n        }\n\n        public static IAsyncObservable<Unit> FromAsync(Func<CancellationToken, Task> actionAsync)\n        {\n            if (actionAsync == null)\n                throw new ArgumentNullException(nameof(actionAsync));","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/FromAsync.cs#L34-L70","documentation":"This FromAsync overload wraps a Func<Task> action into an async observable and throws ArgumentNullException immediately when actionAsync is null. The delegate is required since there is no meaningful asynchronous action to subscribe to otherwise. Validation happens eagerly at call time, not at subscription.","triggerScenarios":"Calling AsyncObservable.FromAsync((Func<Task>)null) or passing a Task-returning delegate variable that was never assigned (e.g. a method group resolved via reflection or an uninitialized field).","commonSituations":"Conditional wiring of pipelines where the action delegate is picked from a dictionary/config and the key is missing, or passing the result of a factory method that returned null.","solutions":["Pass a valid Task-returning delegate, e.g. FromAsync(() => DoWorkAsync()).","Guard the delegate before the call: if (actionAsync == null) throw/return default pipeline.","If the action may be absent, use Defer or an empty observable instead of FromAsync with null."],"exampleFix":"// before\nFunc<Task> action = GetAction(); // may return null\nvar xs = AsyncObservable.FromAsync(action);\n// after\nvar xs = action != null ? AsyncObservable.FromAsync(action) : AsyncObservable.Empty<Unit>();","handlingStrategy":"validation","validationCode":"if (actionAsync is null) throw new InvalidOperationException(\"actionAsync delegate required\");","typeGuard":"bool HasAction(Func<Task> a) => a is not null;","tryCatchPattern":"try { var xs = AsyncObservable.FromAsync(actionAsync); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"actionAsync\") { xs = AsyncObservable.Empty<Unit>(); }","preventionTips":["Use method groups (FromAsync(DoWorkAsync)) instead of nullable delegate variables","Null-check delegates fetched from registries or reflection before use","Model 'no work' as Empty observable, not a null delegate"],"tags":["argument-null","delegate","fromasync","argument-validation"],"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"}