{"record":{"id":"b37e921eb869a7df","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-second","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(second))","messagePattern":"throw new ArgumentNullException\\(nameof\\(second\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs","lineNumber":1148,"sourceCode":"        /// <summary>\n        /// Runs two observable sequences in parallel and combines their last elements.\n        /// </summary>\n        /// <typeparam name=\"TSource1\">The type of the elements in the first source sequence.</typeparam>\n        /// <typeparam name=\"TSource2\">The type of the elements in the second source sequence.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence, returned by the selector function.</typeparam>\n        /// <param name=\"first\">First observable sequence.</param>\n        /// <param name=\"second\">Second observable sequence.</param>\n        /// <param name=\"resultSelector\">Result selector function to invoke with the last elements of both sequences.</param>\n        /// <returns>An observable sequence with the result of calling the selector function with the last elements of both input sequences.</returns>\n        /// <exception cref=\"ArgumentNullException\">\n        /// <paramref name=\"first\" /> or <paramref name=\"second\" /> or <paramref name=\"resultSelector\" /> is null.</exception>\n        [Experimental]\n        public static IQbservable<TResult> ForkJoin<TSource1, TSource2, TResult>(this IQbservable<TSource1> first, IObservable<TSource2> second, Expression<Func<TSource1, TSource2, TResult>> resultSelector)\n        {\n            if (first == null)\n                throw new ArgumentNullException(nameof(first));\n            if (second == null)\n                throw new ArgumentNullException(nameof(second));\n            if (resultSelector == null)\n                throw new ArgumentNullException(nameof(resultSelector));\n\n            return first.Provider.CreateQuery<TResult>(\n                Expression.Call(\n                    null,\n                    new Func<IQbservable<TSource1>, IObservable<TSource2>, Expression<Func<TSource1, TSource2, TResult>>, IQbservable<TResult>>(ForkJoin<TSource1, TSource2, TResult>).Method,\n                    first.Expression,\n                    GetSourceExpression(second),\n                    resultSelector\n                )\n            );\n        }\n#endif\n\n#if !STABLE\n        /// <summary>\n        /// Returns an observable sequence that is the result of invoking the selector on the source sequence, without sharing subscriptions.","sourceCodeStart":1130,"sourceCodeEnd":1166,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs#L1130-L1166","documentation":"In the Qbservable (expression-tree) ForkJoin, the second observable sequence is null; the provider validates it because the IQueryable expression for the parallel last-element join cannot be built with a missing operand. Fix: pass a non-null IQbservable/IObservable for the second argument.","triggerScenarios":"Calling first.ForkJoin(null, resultSelector) or passing a null observable variable as the second source.","commonSituations":"A source observable that is null because an optional service or config-driven producer did not create it.","solutions":["Supply a non-null IObservable as second","Null-check second before calling ForkJoin","Replace null with Observable.Empty<TSource2>() if 'no source' is intended"],"exampleFix":"// before\nfirst.ForkJoin(null, (a, b) => a + b);\n// after\nfirst.ForkJoin(second ?? Observable.Empty<int>().AsQbservable(), (a, b) => a + b);","handlingStrategy":"validation","validationCode":"if (second is null) throw new ArgumentNullException(nameof(second));","typeGuard":"bool IsValidSecond<T>(IObservable<T> o) => o is not null;","tryCatchPattern":"try { var q = first.ForkJoin(second, selector); } catch (ArgumentNullException ex) when (ex.ParamName == \"second\") { /* handle null second */ }","preventionTips":["Substitute Observable.Empty for absent sources instead of null","Null-check observables received from external services"],"tags":["csharp","null-argument","rx","qbservable"],"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"}