{"record":{"id":"a410c1e2584b8e28","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-resultselector-withlatestfrom","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'resultSelector')","messagePattern":"Value cannot be null\\. \\(Parameter 'resultSelector'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/WithLatestFrom.cs","lineNumber":43,"sourceCode":"                    var (firstObserver, secondObserver) = AsyncObserver.WithLatestFrom(observer);\n\n                    // REVIEW: Consider concurrent subscriptions.\n\n                    var firstSubscription = await first.SubscribeSafeAsync(firstObserver).ConfigureAwait(false);\n                    var secondSubscription = await second.SubscribeSafeAsync(secondObserver).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(firstSubscription, secondSubscription);\n                });\n        }\n\n        public static IAsyncObservable<TResult> WithLatestFrom<TFirst, TSecond, TResult>(this IAsyncObservable<TFirst> first, IAsyncObservable<TSecond> second, Func<TFirst, TSecond, 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 CreateAsyncObservable<TResult>.From(\n                first,\n                (second, resultSelector),\n                static async (first, state, observer) =>\n                {\n                    var (firstObserver, secondObserver) = AsyncObserver.WithLatestFrom(observer, state.resultSelector);\n\n                    // REVIEW: Consider concurrent subscriptions.\n\n                    var firstSubscription = await first.SubscribeSafeAsync(firstObserver).ConfigureAwait(false);\n                    var secondSubscription = await state.second.SubscribeSafeAsync(secondObserver).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(firstSubscription, secondSubscription);\n                });\n        }\n\n        public static IAsyncObservable<TResult> WithLatestFrom<TFirst, TSecond, TResult>(this IAsyncObservable<TFirst> first, IAsyncObservable<TSecond> second, Func<TFirst, TSecond, ValueTask<TResult>> resultSelector)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/WithLatestFrom.cs#L25-L61","documentation":"WithLatestFrom's resultSelector is invoked for every source value to combine it with the latest value of the second stream. A null selector cannot be invoked, so the operator throws ArgumentNullException with parameter name 'resultSelector' during eager validation in first.WithLatestFrom(second, resultSelector).","triggerScenarios":"Calling first.WithLatestFrom(second, resultSelector) with a null delegate, e.g. a selector resolved from configuration/DI that failed to bind, or a lambda variable left null in conditional pipeline construction.","commonSituations":"Reflection-based or DI-based composition where the projection delegate could not be created; config-driven pipelines with an invalid or missing selector key; refactors renaming the selector and defaulting it to null.","solutions":["Pass a concrete selector, e.g. (first, second) => (first, second) for the default pairing behavior.","If no projection is needed, use the two-parameter WithLatestFrom(first, second) overload instead.","Fix the delegate resolution (DI registration, config binding) so it produces a non-null Func.","Add a null check with a clear message before composing the pipeline."],"exampleFix":"// before\nvar result = first.WithLatestFrom(second, null);\n// after\nvar result = first.WithLatestFrom(second, (f, s) => (f, s));","handlingStrategy":"validation","validationCode":"if (resultSelector is null) throw new ArgumentNullException(nameof(resultSelector));\nvar result = first.WithLatestFrom(second, resultSelector);","typeGuard":"bool HasSelector<T1, T2, R>(Func<T1, T2, R> f) => f is not null;","tryCatchPattern":"try\n{\n    var result = first.WithLatestFrom(second, resultSelector);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"resultSelector\")\n{\n    // fall back to tuple-pairing default selector\n    var result = first.WithLatestFrom(second, (f, s) => (f, s));\n}","preventionTips":["Write selectors as inline lambdas so they can never be null.","If no projection is needed, use the two-parameter overload instead of a null selector.","Validate DI/config-resolved delegates immediately after binding.","Enable nullable reference types so null delegate arguments fail at compile time."],"tags":["argument-null","async-rx","withlatestfrom-operator","result-selector"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}