{"record":{"id":"686b41589a77e57b","repo":"dotnet/reactive","slug":"scheduler-observableex","errorCode":null,"errorMessage":"scheduler","messagePattern":"scheduler","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/ObservableEx.cs","lineNumber":87,"sourceCode":"        /// <param name=\"scheduler\">Scheduler on which to perform the expansion by enumerating the internal queue of obtained sequences.</param>\n        /// <returns>An observable sequence containing all the elements produced by the recursive expansion.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"selector\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        [Experimental]\n        public static IObservable<TSource> Expand<TSource>(this IObservable<TSource> source, Func<TSource, IObservable<TSource>> selector, IScheduler scheduler)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (selector == null)\n            {\n                throw new ArgumentNullException(nameof(selector));\n            }\n\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return s_impl.Expand(source, selector, scheduler);\n        }\n\n        /// <summary>\n        /// Expands an observable sequence by recursively invoking selector.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence and each of the recursively expanded sources obtained by running the selector function.</typeparam>\n        /// <param name=\"source\">Source sequence with the initial elements.</param>\n        /// <param name=\"selector\">Selector function to invoke for each produced element, resulting in another sequence to which the selector will be invoked recursively again.</param>\n        /// <returns>An observable sequence containing all the elements produced by the recursive expansion.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"selector\"/> is null.</exception>\n        [Experimental]\n        public static IObservable<TSource> Expand<TSource>(this IObservable<TSource> source, Func<TSource, IObservable<TSource>> selector)\n        {\n            if (source == null)\n            {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/ObservableEx.cs#L69-L105","documentation":"Expand(source, selector, scheduler) uses the IScheduler to control timing/concurrency of recursive expansion. A null scheduler throws ArgumentNullException immediately. Passing Scheduler.Default or an explicit scheduler resolves it.","triggerScenarios":"Calling Expand with scheduler = null, typically from an uninitialized injected scheduler or a static property that has not been assigned.","commonSituations":"Missing IScheduler DI registration, unit tests passing null instead of TestScheduler, app-startup ordering where the scheduler field is read before initialization.","solutions":["Pass Scheduler.Default, Scheduler.TaskPool, or Scheduler.CurrentThread","Drop the scheduler overload and call the two-argument Expand(source, selector), which uses the default scheduler","Fix initialization/DI ordering so the injected scheduler is set before pipelines are built"],"exampleFix":"// before\nvar expanded = source.Expand(x => Next(x), sched); // sched null\n// after\nvar expanded = source.Expand(x => Next(x), sched ?? Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (scheduler == null) throw new ArgumentNullException(nameof(scheduler), \"Expand requires a scheduler; use Scheduler.Default.\");","typeGuard":"bool IsValidScheduler(IScheduler s) => s is not null;","tryCatchPattern":"try { var expanded = source.Expand(selector, scheduler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"scheduler\") { log.Error(\"Scheduler not provided for Expand\", ex); }","preventionTips":["Use the two-argument Expand overload when no custom scheduler is needed","Coalesce injected schedulers with Scheduler.Default","Add DI startup assertions that IScheduler resolves non-null"],"tags":["csharp","null-argument","scheduler","reactive-extensions"],"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"}