{"record":{"id":"8cc91dfd29c012bd","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-options","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'options')","messagePattern":"Value cannot be null\\. \\(Parameter 'options'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs","lineNumber":1101,"sourceCode":"        /// <param name=\"options\">Controls how the tasks's progress is observed.</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, TaskObservationOptions options)\n        {\n            if (functionAsync == null)\n            {\n                throw new ArgumentNullException(nameof(functionAsync));\n            }\n\n            if (options == null)\n            {\n                throw new ArgumentNullException(nameof(options));\n            }\n\n            return s_impl.StartAsync(functionAsync, options.ToValue());\n        }\n\n        /// <summary>\n        /// Invokes the asynchronous function, surfacing the result through an observable sequence.\n        /// The CancellationToken is shared by all subscriptions on the resulting observable sequence. See the remarks section for more information.\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        /// <item><description>","sourceCodeStart":1083,"sourceCodeEnd":1119,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Async.cs#L1083-L1119","documentation":"Observable.StartAsync(functionAsync, TaskObservationOptions) throws ArgumentNullException when options is null. TaskObservationOptions controls scheduling and exception-after-unsubscribe behavior; without it the library cannot build the TaskObservationOptions.Value it needs, so it fails fast.","triggerScenarios":"Calling Observable.StartAsync<TResult>(Func<Task<TResult>>, TaskObservationOptions) with options == null, e.g. options built from a nullable configuration object or defaulting code path that never assigned it.","commonSituations":"Config-driven setups where an options section was absent, factory methods returning null instead of default options, or refactors that removed a default instance.","solutions":["Pass a constructed TaskObservationOptions instance, or use the IScheduler overload with a concrete scheduler","Use the parameterless-ish alternatives: StartAsync(functionAsync) or StartAsync(functionAsync, scheduler) which build default options internally","Coalesce to a default options object when loaded from configuration"],"exampleFix":"// before\nvar opts = config.Get<TaskObservationOptions>(); // may be null\nObservable.StartAsync(workAsync, opts);\n// after\nvar opts = config.Get<TaskObservationOptions>() ?? new TaskObservationOptions(Scheduler.Default);\nObservable.StartAsync(workAsync, opts);","handlingStrategy":"validation","validationCode":"if (options == null) throw new ArgumentNullException(nameof(options));\nObservable.StartAsync(functionAsync, options);","typeGuard":"bool HasOptions(TaskObservationOptions o) => o is not null;","tryCatchPattern":"try { Observable.StartAsync(functionAsync, options); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"options\") { Observable.StartAsync(functionAsync, Scheduler.Default); }","preventionTips":["Default options at the configuration boundary, never null","Prefer the scheduler overload or plain overload to avoid manual option construction","Return default instances (not null) from options factories"],"tags":["csharp","rx","async","null-argument","options"],"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"}