{"record":{"id":"6457ddaf612ab919","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-first","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(first))","messagePattern":"throw new ArgumentNullException\\(nameof\\(first\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs","lineNumber":1146,"sourceCode":"\n#if !STABLE\n        /// <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","sourceCodeStart":1128,"sourceCodeEnd":1164,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs#L1128-L1164","documentation":"The two-source ForkJoin overload throws ArgumentNullException when the first IQbservable<TSource1> is null. The instance's Provider property is needed to build the result query, so null is rejected up front.","triggerScenarios":"Calling first.ForkJoin(second, resultSelector) where the extension method is invoked on a null IQbservable reference (allowed in C# for extension methods until the guard runs).","commonSituations":"A LINQ query variable that was null because an earlier qbservable factory returned null, or calling the static form ForkJoin(null, second, selector).","solutions":["Ensure the first argument is a valid non-null IQbservable","Null-check the qbservable before chaining ForkJoin","Trace why the upstream query construction returned null"],"exampleFix":"// before\nIQbservable<int> first = null;\nvar q = first.ForkJoin(second, (a, b) => a + b);\n// after\nif (first == null) throw new InvalidOperationException(\"first is null\");\nvar q = first.ForkJoin(second, (a, b) => a + b);","handlingStrategy":"validation","validationCode":"if (first is null) throw new ArgumentNullException(nameof(first));","typeGuard":"bool IsValidFirst<T>(IQbservable<T> q) => q is not null;","tryCatchPattern":"try { var q = first.ForkJoin(second, selector); } catch (ArgumentNullException ex) when (ex.ParamName == \"first\") { /* handle null first */ }","preventionTips":["Verify the qbservable chain produced a non-null result before further chaining","Enable nullable reference types"],"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"}