{"record":{"id":"9d9674ca0415bc06","repo":"dotnet/reactive","slug":"nameof-source-observable-conversions","errorCode":null,"errorMessage":"nameof(source)","messagePattern":"nameof\\(source\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Conversions.cs","lineNumber":26,"sourceCode":"namespace System.Reactive.Linq\n{\n    public static partial class Observable\n    {\n        #region + Subscribe +\n\n        /// <summary>\n        /// Subscribes an observer to an enumerable sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Enumerable sequence to subscribe to.</param>\n        /// <param name=\"observer\">Observer that will receive notifications from the enumerable sequence.</param>\n        /// <returns>Disposable object that can be used to unsubscribe the observer from the enumerable</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"observer\"/> is null.</exception>\n        public static IDisposable Subscribe<TSource>(this IEnumerable<TSource> source, IObserver<TSource> observer)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (observer == null)\n            {\n                throw new ArgumentNullException(nameof(observer));\n            }\n\n            return s_impl.Subscribe(source, observer);\n        }\n\n        /// <summary>\n        /// Subscribes an observer to an enumerable sequence, using the specified scheduler to run the enumeration loop.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Enumerable sequence to subscribe to.</param>\n        /// <param name=\"observer\">Observer that will receive notifications from the enumerable sequence.</param>\n        /// <param name=\"scheduler\">Scheduler to perform the enumeration on.</param>\n        /// <returns>Disposable object that can be used to unsubscribe the observer from the enumerable</returns>","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Conversions.cs#L8-L44","documentation":"The IEnumerable-to-IObservable conversion Subscribe extension throws ArgumentNullException when the enumerable source is null. This operator subscribes an IObserver to the enumerable; Rx validates both arguments eagerly in the public wrapper before delegating to the implementation.","triggerScenarios":"Calling enumerable.Subscribe(observer) where the IEnumerable<TSource> is null — e.g. a method returning null for 'no data', or an uninitialized collection field.","commonSituations":"Happens when bridging legacy/LINQ data sources into Rx pipelines: a repository or parser returns null instead of an empty sequence and the result is converted to an observable.","solutions":["Ensure the enumerable is non-null before converting; treat null as an empty sequence at the source.","Use Enumerable.Empty<TSource>() as the fallback when there is no data.","Have producers return empty collections instead of null (standard .NET collection guidelines)."],"exampleFix":"// before\nIEnumerable<int> data = repo.Query(); // may be null\ndata.Subscribe(observer);\n// after\nvar data = repo.Query() ?? Enumerable.Empty<int>();\ndata.Subscribe(observer);","handlingStrategy":"validation","validationCode":"if (source is null) source = Enumerable.Empty<T>();\nvar d = source.Subscribe(observer);","typeGuard":"static bool IsValid<T>(IEnumerable<T>? e) => e is not null;","tryCatchPattern":"try { var d = source.Subscribe(observer); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { log.Error(\"Null enumerable passed to Subscribe\"); }","preventionTips":["Have data loaders return Enumerable.Empty<T>() instead of null.","Follow .NET guidelines: collections/sequences should never be null.","Coalesce at the boundary: source ?? Enumerable.Empty<T>() before bridging to Rx."],"tags":["rx","argumentnull","ienumerable","null-check"],"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"}