{"record":{"id":"bfce67a6eea09d0a","repo":"dotnet/reactive","slug":"source-observableex","errorCode":null,"errorMessage":"source","messagePattern":"source","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/ObservableEx.cs","lineNumber":77,"sourceCode":"        #endregion\n\n        #region Expand\n\n        /// <summary>\n        /// Expands an observable sequence by recursively invoking selector, using the specified scheduler to enumerate the queue of obtained sequences.\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        /// <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>","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/ObservableEx.cs#L59-L95","documentation":"Experimental Expand(source, selector, scheduler) recursively re-applies selector to each produced value. It validates arguments synchronously and throws ArgumentNullException when the source observable is null. This fail-fast check mirrors the standard Rx operator contract.","triggerScenarios":"Calling Expand with a null IObservable<TSource>, usually from an unassigned field or a factory that returned null before the Expand call.","commonSituations":"DI-resolved streams that failed to bind, chaining after optional operators that can return null, pipeline construction where an earlier stage was skipped due to a flag.","solutions":["Guarantee the source observable is non-null before Expand","Substitute a default (Observable.Empty<TSource>()) when the source may legitimately be absent","Trace where the null originated — often an earlier operator or a null-returning factory"],"exampleFix":"// before\nvar expanded = source.Expand(x => GetChildren(x), Scheduler.Default); // source null\n// after\nvar expanded = (source ?? Observable.Empty<Node>()).Expand(x => GetChildren(x), Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (source == null) throw new ArgumentNullException(nameof(source), \"Expand requires a non-null source observable.\");","typeGuard":"bool IsValid<TSource>(IObservable<TSource> s) => s is not null;","tryCatchPattern":"try { var expanded = source.Expand(selector, scheduler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { log.Error(\"Expand source was null\", ex); }","preventionTips":["Initialize observable streams eagerly; prefer Subjects or Observable.Defer over null","Null-check upstream factory results before composing","Enable nullable reference types to catch uninitialized streams"],"tags":["csharp","null-argument","experimental-api","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"}