{"record":{"id":"7f0134bb6d284a75","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-resultselector-7f0134","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(resultSelector))","messagePattern":"throw new ArgumentNullException\\(nameof\\(resultSelector\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs","lineNumber":1150,"sourceCode":"        /// </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.\n        /// This operator allows for a fluent style of writing queries that use the same sequence multiple times.\n        /// </summary>","sourceCodeStart":1132,"sourceCodeEnd":1168,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs#L1132-L1168","documentation":"The two-source ForkJoin overload throws ArgumentNullException when the resultSelector expression is null. A non-null Expression<Func<TSource1,TSource2,TResult>> is required because it is embedded in the MethodCallExpression sent to the IQbservable provider.","triggerScenarios":"Calling first.ForkJoin(second, null), e.g. passing a null lambda variable or a null result from a selector factory.","commonSituations":"Conditionally built selector expressions that ended up null, or reflection-based code that failed to compile the lambda.","solutions":["Pass a real lambda expression, e.g. (a, b) => new { a, b }","Ensure any selector built dynamically is compiled/created before the call","Null-check the selector variable before invoking ForkJoin"],"exampleFix":"// before\nExpression<Func<int, int, int>> selector = null;\nfirst.ForkJoin(second, selector);\n// after\nExpression<Func<int, int, int>> selector = (a, b) => a + b;\nfirst.ForkJoin(second, selector);","handlingStrategy":"validation","validationCode":"if (resultSelector is null) throw new ArgumentNullException(nameof(resultSelector));","typeGuard":"bool IsValidSelector<T1,T2,R>(Expression<Func<T1,T2,R>> s) => s is not null;","tryCatchPattern":"try { var q = first.ForkJoin(second, selector); } catch (ArgumentNullException ex) when (ex.ParamName == \"resultSelector\") { /* handle null selector */ }","preventionTips":["Always pass lambda expressions inline so the compiler guarantees non-null","Guard dynamically built expression factories against null returns"],"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"}