{"record":{"id":"443f116e3d9df822","repo":"dotnet/reactive","slug":"observer-takeuntil","errorCode":null,"errorMessage":"observer","messagePattern":"observer","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/TakeUntil.cs","lineNumber":88,"sourceCode":"                source,\n                (endTime, scheduler),\n                static async (source, state, observer) =>\n                {\n                    var (sourceObserver, timer) = await AsyncObserver.TakeUntil(observer, state.endTime, state.scheduler).ConfigureAwait(false);\n\n                    var subscription = await source.SubscribeSafeAsync(sourceObserver).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(subscription, timer);\n                });\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static (IAsyncObserver<TSource>, IAsyncObserver<TUntil>) TakeUntil<TSource, TUntil>(IAsyncObserver<TSource> observer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            var gate = new AsyncGate();\n\n            return\n                (\n                    Create<TSource>(\n                        async x =>\n                        {\n                            using (await gate.LockAsync().ConfigureAwait(false))\n                            {\n                                await observer.OnNextAsync(x).ConfigureAwait(false);\n                            }\n                        },\n                        async ex =>\n                        {\n                            using (await gate.LockAsync().ConfigureAwait(false))\n                            {\n                                await observer.OnErrorAsync(ex).ConfigureAwait(false);","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/TakeUntil.cs#L70-L106","documentation":"The AsyncObserver.TakeUntil<TSource, TUntil>(observer) factory throws ArgumentNullException because the downstream observer argument was null. This observer-level factory creates the paired (source, until) observers wired through an AsyncGate; it requires a non-null downstream IAsyncObserver to forward emissions to. The parameter name 'observer' identifies the null argument.","triggerScenarios":"Calling AsyncObserver.TakeUntil<TSource, TUntil>(null) when composing custom observer pipelines.","commonSituations":"Building custom operators where the downstream observer comes from an upstream subscription that returned null; mis-ordered composition where the observer is created after it is passed; test scaffolding that forgot to instantiate the observer.","solutions":["Pass the actual downstream IAsyncObserver you intend to forward to (e.g. the one obtained from CreateAsyncObserver or another operator factory).","Check the composition order — create the downstream observer before calling AsyncObserver.TakeUntil.","If writing a custom operator, assert observer != null at the entry of your SubscribeSafeAsync implementation to fail fast with a clearer message."],"exampleFix":"// before\nvar (srcObs, untilObs) = AsyncObserver.TakeUntil<int, object>(null);\n// after\nvar downstream = AsyncObserver.Create<int>(onNextAsync: ...);\nvar (srcObs, untilObs) = AsyncObserver.TakeUntil<int, object>(downstream);","handlingStrategy":"validation","validationCode":"if (observer == null) throw new InvalidOperationException(\"downstream observer must be created before TakeUntil\");","typeGuard":"bool HasObserver<T>(IAsyncObserver<T>? o) => o is not null;","tryCatchPattern":"try { var pair = AsyncObserver.TakeUntil<int, object>(observer); } catch (ArgumentNullException ex) when (ex.ParamName == \"observer\") { /* re-create downstream observer and retry composition */ }","preventionTips":["Always create the downstream observer (AsyncObserver.Create or upstream factory) before composing operator observers.","In custom operators, assert non-null observers at the entry of SubscribeSafeAsync.","Keep observer composition synchronous and ordered so references cannot be lost."],"tags":["argument-null","observer","takeuntil","reactive-extensions"],"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"}