{"record":{"id":"4aa389b4ffafefdd","repo":"dotnet/reactive","slug":"argumentnullexception-nameof-first","errorCode":null,"errorMessage":"ArgumentNullException(nameof(first))","messagePattern":"ArgumentNullException\\(nameof\\(first\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Multiple.cs","lineNumber":357,"sourceCode":"        }\n\n        #endregion\n\n        #region + Concat +\n\n        /// <summary>\n        /// Concatenates the second observable sequence to the first observable sequence upon successful termination of the first.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequences.</typeparam>\n        /// <param name=\"first\">First observable sequence.</param>\n        /// <param name=\"second\">Second observable sequence.</param>\n        /// <returns>An observable sequence that contains the elements of the first sequence, followed by those of the second the sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"first\"/> or <paramref name=\"second\"/> is null.</exception>\n        public static IObservable<TSource> Concat<TSource>(this IObservable<TSource> first, IObservable<TSource> second)\n        {\n            if (first == null)\n            {\n                throw new ArgumentNullException(nameof(first));\n            }\n\n            if (second == null)\n            {\n                throw new ArgumentNullException(nameof(second));\n            }\n\n            return s_impl.Concat(first, second);\n        }\n\n        /// <summary>\n        /// Concatenates all of the specified observable sequences, as long as the previous observable sequence terminated successfully.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequences.</typeparam>\n        /// <param name=\"sources\">Observable sequences to concatenate.</param>\n        /// <returns>An observable sequence that contains the elements of each given sequence, in sequential order.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"sources\"/> is null.</exception>\n        public static IObservable<TSource> Concat<TSource>(params IObservable<TSource>[] sources)","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Multiple.cs#L339-L375","documentation":"Concat<TSource>(first, second) throws ArgumentNullException when the first observable is null (Observable.Multiple.cs:357). Rx checks arguments eagerly and in order, so this fires before the second-source check. The error is thrown synchronously at the call site rather than being delivered through OnError.","triggerScenarios":"Calling first.Concat(second) or Observable.Concat(first, second) where the first IObservable is null.","commonSituations":"First stream from an uninitialized Subject or an unregistered event bus lookup; a factory returning null when a feature is disabled; chained pipeline code where an earlier stage produced null instead of an empty observable.","solutions":["Initialize the first observable before concatenating; use Observable.Empty<TSource>() when there is genuinely nothing to emit.","Coalesce: (first ?? Observable.Empty<TSource>()).Concat(second).","Fix the upstream producer so it returns an empty observable instead of null."],"exampleFix":"// before\nIObservable<Event> history = LoadHistory(); // can return null\nvar all = history.Concat(live);\n// after\nvar all = (LoadHistory() ?? Observable.Empty<Event>()).Concat(live);","handlingStrategy":"validation","validationCode":"if (first == null) throw new InvalidOperationException(\"first source required\"); // or: first ??= Observable.Empty<TSource>();","typeGuard":"bool IsStreamReady(IObservable<TSource>? first) => first is not null;","tryCatchPattern":"try { var result = first.Concat(second); } catch (ArgumentNullException ex) when (ex.ParamName == \"first\") { /* fall back to Observable.Empty<TSource>() */ }","preventionTips":["Producers should return empty observables, never null.","Enable nullable reference types to catch null streams at compile time.","Initialize event-bus/Subject lookups before pipeline construction."],"tags":["rx","argument-null","concat"],"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"}