{"record":{"id":"09af9b901e7c8eb5","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-function","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'function')","messagePattern":"Value cannot be null\\. \\(Parameter 'function'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs","lineNumber":991,"sourceCode":"\n        /// <summary>\n        /// Invokes the specified function asynchronously, surfacing the result through an observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type of the result returned by the function.</typeparam>\n        /// <param name=\"function\">Function to run asynchronously.</param>\n        /// <returns>An observable sequence exposing the function's result value, or an exception.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"function\"/> is null.</exception>\n        /// <remarks>\n        /// <list type=\"bullet\">\n        /// <item><description>The function is called 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> Start<TResult>(Func<TResult> function)\n        {\n            if (function == null)\n            {\n                throw new ArgumentNullException(nameof(function));\n            }\n\n            return s_impl.Start(function);\n        }\n\n        /// <summary>\n        /// Invokes the specified function asynchronously on the specified scheduler, surfacing the result through an observable sequence\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type of the result returned by the function.</typeparam>\n        /// <param name=\"function\">Function to run asynchronously.</param>\n        /// <param name=\"scheduler\">Scheduler to run the function on.</param>\n        /// <returns>An observable sequence exposing the function's result value, or an exception.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"function\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        /// <remarks>\n        /// <list type=\"bullet\">\n        /// <item><description>The function is called 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":973,"sourceCodeEnd":1009,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs#L973-L1009","documentation":"Observable.Start<TResult>(Func<TResult>) invokes the given function synchronously-or-on-schedule and publishes its result as an observable. Rx validates the function eagerly and throws ArgumentNullException with Parameter 'function' when null, since there is no computation to run.","triggerScenarios":"Calling Observable.Start(function) with a null Func<TResult> (line 991 in Observable.Async.cs), e.g. a null delegate field, an unassigned lambda variable, or a factory that returned null.","commonSituations":"Dependency-injected computation delegate not registered; conditional logic skipped assignment; passing the result of a lookup (e.g. dictionary of delegates) that missed.","solutions":["Pass a valid non-null Func<TResult> to Observable.Start.","Ensure any delegate field/dependency is initialized before calling Start.","If the computation may be absent, fall back to Observable.Empty<TResult>() or a default result instead of Start(null)."],"exampleFix":"// before\nFunc<int> compute = config.Computations[\"fast\"] ?? null;\nObservable.Start(compute);\n// after\nFunc<int> compute = config.Computations[\"fast\"];\nObservable.Start(() => compute != null ? compute() : 0);","handlingStrategy":"validation","validationCode":"if (function is null) throw new ArgumentNullException(nameof(function));\nvar observable = Observable.Start(function);","typeGuard":"static bool IsValidFunction<TResult>(Func<TResult> function) => function is not null;","tryCatchPattern":"try { var obs = Observable.Start(function); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"function\") { obs = Observable.Empty<TResult>(); }","preventionTips":["Check delegate-producing lookups (dictionaries, DI) for misses before calling Start.","Use Observable.Empty<TResult>() or a default when no computation is available.","Enable nullable reference types to catch unassigned Func fields at compile time."],"tags":["dotnet","rx","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-23T08:17:48.524Z"}