{"record":{"id":"790d80a7e94cf95b","repo":"dotnet/reactive","slug":"argumentnullexception-nameof-sources","errorCode":null,"errorMessage":"ArgumentNullException(nameof(sources))","messagePattern":"ArgumentNullException\\(nameof\\(sources\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Multiple.cs","lineNumber":294,"sourceCode":"\n            return s_impl.CombineLatest(first, second, resultSelector);\n        }\n\n        /// <summary>\n        /// Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequences.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence, returned by the selector function.</typeparam>\n        /// <param name=\"sources\">Observable sources.</param>\n        /// <param name=\"resultSelector\">Function to invoke whenever any of the sources produces an element. For efficiency, the input list is reused after the selector returns. Either aggregate or copy the values during the function call.</param>\n        /// <returns>An observable sequence containing the result of combining elements of the sources using the specified result selector function.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"sources\"/> or <paramref name=\"resultSelector\"/> is null.</exception>\n        /// <remarks>If a non-empty source completes, its very last value will be used for creating subsequent combinations until all sources terminate.</remarks>\n        public static IObservable<TResult> CombineLatest<TSource, TResult>(this IEnumerable<IObservable<TSource>> sources, Func<IList<TSource>, TResult> resultSelector)\n        {\n            if (sources == null)\n            {\n                throw new ArgumentNullException(nameof(sources));\n            }\n\n            if (resultSelector == null)\n            {\n                throw new ArgumentNullException(nameof(resultSelector));\n            }\n\n            return s_impl.CombineLatest(sources, resultSelector);\n        }\n\n        /// <summary>\n        /// Merges the specified observable sequences into one observable sequence by emitting a list with the latest source elements whenever any of the observable sequences produces an element.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequences, and in the lists in the result sequence.</typeparam>\n        /// <param name=\"sources\">Observable sources.</param>\n        /// <returns>An observable sequence containing lists of the latest elements of the sources.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"sources\"/> is null.</exception>\n        /// <remarks>If a non-empty source completes, its very last value will be used for creating subsequent combinations until all sources terminate.</remarks>","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Multiple.cs#L276-L312","documentation":"The IEnumerable overload CombineLatest<TSource,TResult>(sources, resultSelector) throws ArgumentNullException when the sources sequence is null (Observable.Multiple.cs:294). Validation runs eagerly at call time, before the resultSelector check. This fail-fast guard prevents the error from surfacing later inside the subscription pipeline.","triggerScenarios":"Calling sources.CombineLatest(selector) with a null IEnumerable<IObservable<TSource>>, e.g. Observable.CombineLatest(GetStreams(), selector) where GetStreams() returns null.","commonSituations":"Streams collected from a dictionary lookup that returned null; a list built conditionally and left uninitialized; framework code passing a nullable collection straight through.","solutions":["Initialize sources to an empty enumerable when there are no streams: Enumerable.Empty<IObservable<TSource>>().","Coalesce at the call site: (sources ?? Enumerable.Empty<IObservable<TSource>>()).CombineLatest(selector).","Fix the producer method so it returns an empty collection rather than null."],"exampleFix":"// before\nvar streams = registry.GetStreams(name); // can return null\nvar combined = streams.CombineLatest(xs => xs.Sum());\n// after\nvar streams = registry.GetStreams(name) ?? Enumerable.Empty<IObservable<int>>();\nvar combined = streams.CombineLatest(xs => xs.Sum());","handlingStrategy":"validation","validationCode":"if (sources == null) throw new InvalidOperationException(\"sources required\"); // or: sources ??= Enumerable.Empty<IObservable<TSource>>();","typeGuard":"bool HasSources(IEnumerable<IObservable<TSource>>? sources) => sources is not null;","tryCatchPattern":"try { var result = sources.CombineLatest(selector); } catch (ArgumentNullException ex) when (ex.ParamName == \"sources\") { /* fall back to empty sequence */ }","preventionTips":["Return empty collections instead of null from lookup methods.","Coalesce at pipeline-build time.","Guard deserialized config collections before use."],"tags":["rx","argument-null","combinelatest"],"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"}