{"record":{"id":"0a887ce2f1dd73d3","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-observer-withlatestfrom","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'observer')","messagePattern":"Value cannot be null\\. \\(Parameter 'observer'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/WithLatestFrom.cs","lineNumber":92,"sourceCode":"                {\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\n    public partial class AsyncObserver\n    {\n        public static (IAsyncObserver<TFirst>, IAsyncObserver<TSecond>) WithLatestFrom<TFirst, TSecond, TResult>(IAsyncObserver<TResult> observer, Func<TFirst, TSecond, TResult> resultSelector)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (resultSelector == null)\n                throw new ArgumentNullException(nameof(resultSelector));\n\n            return WithLatestFrom<TFirst, TSecond, TResult>(observer, (x, y) => new ValueTask<TResult>(resultSelector(x, y)));\n        }\n\n        public static (IAsyncObserver<TFirst>, IAsyncObserver<TSecond>) WithLatestFrom<TFirst, TSecond, TResult>(IAsyncObserver<TResult> observer, Func<TFirst, TSecond, ValueTask<TResult>> resultSelector)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (resultSelector == null)\n                throw new ArgumentNullException(nameof(resultSelector));\n\n            var gate = new AsyncGate();\n\n            async ValueTask OnErrorAsync(Exception ex)\n            {\n                using (await gate.LockAsync().ConfigureAwait(false))","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/WithLatestFrom.cs#L74-L110","documentation":"ArgumentNullException raised by the AsyncObserver.WithLatestFrom factory overload because the target IAsyncObserver<TResult> is null. This overload creates the paired (first, second) observers that feed a WithLatestFrom pipeline and validates the downstream observer first.","triggerScenarios":"Calling AsyncObserver.WithLatestFrom<TFirst,TSecond,TResult>(null, resultSelector) with a sync Func selector, e.g. when building custom operator plumbing and the downstream observer is null.","commonSituations":"Composing custom operators where the observer comes from a CreateAsyncObservable callback whose argument was null; passing a not-yet-initialized observer field.","solutions":["Pass a valid downstream IAsyncObserver<TResult>","Check the factory/subscription code that was supposed to supply the observer","Guard the call site before invoking the observer factory"],"exampleFix":"// before\nvar (obs1, obs2) = AsyncObserver.WithLatestFrom<int, int, string>(null, (x, y) => $\"{x}:{y}\");\n// after\nvar downstream = GetObserver(); // must be non-null\nvar (obs1, obs2) = AsyncObserver.WithLatestFrom<int, int, string>(downstream, (x, y) => $\"{x}:{y}\");","handlingStrategy":"validation","validationCode":"if (observer is null) throw new InvalidOperationException(\"Downstream observer must be created before WithLatestFrom observers can be attached.\");","typeGuard":"bool HasObserver<T>(IAsyncObserver<T>? o) => o is not null;","tryCatchPattern":"try { var pair = AsyncObserver.WithLatestFrom<T1,T2,TR>(observer, selector); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\")\n{\n    // observer pipeline mis-wired: log and rethrow with context\n    throw new InvalidOperationException(\"WithLatestFrom requires a subscribed downstream observer.\", ex);\n}","preventionTips":["Only construct AsyncObserver.* pairs inside a CreateAsyncObservable callback where the observer is guaranteed non-null","Assert observer non-null in custom operator wrappers","Keep observer creation and observer-factory calls in the same subscription path"],"tags":["argument-null","asyncrx","observer","argument-validation"],"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"}