{"record":{"id":"918b7d64120fbc95","repo":"dotnet/reactive","slug":"functionasync","errorCode":null,"errorMessage":"functionAsync","messagePattern":"functionAsync","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/StartAsync.cs","lineNumber":19,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Reactive.Concurrency;\nusing System.Reactive.Disposables;\nusing System.Threading;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TSource> StartAsync<TSource>(Func<ValueTask<TSource>> functionAsync) => StartAsync(functionAsync, ImmediateAsyncScheduler.Instance);\n\n        public static IAsyncObservable<TSource> StartAsync<TSource>(Func<ValueTask<TSource>> 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            Task<TSource> task;\n\n            try\n            {\n                task = functionAsync().AsTask();\n            }\n            catch (Exception ex)\n            {\n                return Throw<TSource>(ex);\n            }\n\n            return task.ToAsyncObservable(scheduler);\n        }\n\n        public static IAsyncObservable<TSource> StartAsync<TSource>(Func<CancellationToken, ValueTask<TSource>> functionAsync) => StartAsync(functionAsync, ImmediateAsyncScheduler.Instance);","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/StartAsync.cs#L1-L37","documentation":"StartAsync<TSource>(Func<ValueTask<TSource>>, IAsyncScheduler) throws ArgumentNullException when the functionAsync delegate is null. The operator immediately invokes the delegate to obtain the ValueTask and convert it to a Task, so null is rejected up front.","triggerScenarios":"Calling StartAsync with a null async function delegate, with either the one- or two-argument overload (the one-argument overload forwards to this one).","commonSituations":"Uninitialized Func fields, conditional async handlers that are null, DI or factory returning null for the delegate.","solutions":["Pass a non-null Func<ValueTask<TSource>>","Guard the call site if the delegate is optional","Trace why the delegate source was null"],"exampleFix":"// before\nvar xs = StartAsync(maybeFetch); // maybeFetch is null\n// after\nif (maybeFetch != null) { var xs = StartAsync(maybeFetch); }","handlingStrategy":"validation","validationCode":"if (functionAsync == null) throw new ArgumentNullException(nameof(functionAsync));","typeGuard":"static bool IsValidFunction<TSource>(Func<ValueTask<TSource>> f) => f is not null;","tryCatchPattern":null,"preventionTips":["Check delegate-producing factories/lookups for null returns","Use pattern matching (is not null) before invoking operators","Wrap optional delegates in guard clauses at call sites"],"tags":["argument-null","reactive","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-15T23:17:13.987Z"}