{"record":{"id":"ef3750c4b2372d68","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-observer-catch","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/Catch.cs","lineNumber":110,"sourceCode":"\n                var source = enumerator.Current;\n\n                var (sink, inner) = AsyncObserver.Catch(observer, enumerator);\n\n                var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                return StableCompositeAsyncDisposable.Create(subscription, inner);\n            });\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static (IAsyncObserver<TSource>, IAsyncDisposable) Catch<TSource, TException>(IAsyncObserver<TSource> observer, Func<TException, IAsyncObservable<TSource>> handler)\n            where TException : Exception\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (handler == null)\n                throw new ArgumentNullException(nameof(handler));\n\n            return Catch<TSource, TException>(observer, ex => new ValueTask<IAsyncObservable<TSource>>(handler(ex)));\n        }\n\n        public static (IAsyncObserver<TSource>, IAsyncDisposable) Catch<TSource, TException>(IAsyncObserver<TSource> observer, Func<TException, ValueTask<IAsyncObservable<TSource>>> handler)\n            where TException : Exception\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (handler == null)\n                throw new ArgumentNullException(nameof(handler));\n\n            var subscription = new SingleAssignmentAsyncDisposable();\n\n            var sink = Create<TSource>(\n                observer.OnNextAsync,","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Catch.cs#L92-L128","documentation":"AsyncObserver.Catch<TSource,TException>(observer, handler) builds an observer pair that redirects OnError to the handler's fallback observable. The observer argument is the downstream observer receiving events; passing null leaves the sink nowhere to write, so ArgumentNullException('observer') is thrown first.","triggerScenarios":"Calling the (IAsyncObserver, Func<TException, IAsyncObservable>) overload with a null observer, typically when the observer variable was never assigned or a factory returned null.","commonSituations":"Manually composing observer pipelines where the downstream observer comes from a nullable field, or refactorings that reordered construction so the observer is passed before being created.","solutions":["Create/obtain the observer before wiring the Catch sink","Assert the observer is non-null before calling","Trace where the observer value originates; fix the null-returning source"],"exampleFix":"// before\nvar (sink, disp) = AsyncObserver.Catch<int, TimeoutException>(null, ex => AsyncObservable.Return(ex.StackTrace));\n// after\nvar downstream = AsyncObserver.Create<int>(OnNextAsync, OnErrorAsync, OnCompletedAsync);\nvar (sink, disp) = AsyncObserver.Catch<int, TimeoutException>(downstream, ex => AsyncObservable.Return(ex.StackTrace));","handlingStrategy":"validation","validationCode":"if (observer is null) throw new ArgumentNullException(nameof(observer));","typeGuard":"bool CanWire<T>(IAsyncObserver<T> observer) => observer != null;","tryCatchPattern":"try { var (sink, d) = AsyncObserver.Catch<T, TException>(observer, handler); } catch (ArgumentNullException ex) when (ex.ParamName == \"observer\") { /* fix observer construction */ }","preventionTips":["Construct observers before wiring sinks","Forward observer parameters through non-nullable paths","Initialize observer fields at construction, not lazily"],"tags":["argument-null","observer","rx"],"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"}