{"record":{"id":"d62e277342fd2e81","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-second-catch","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'second')","messagePattern":"Value cannot be null\\. \\(Parameter 'second'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Catch.cs","lineNumber":62,"sourceCode":"            return Create(\n                source,\n                handler,\n                static async (source, handler, observer) =>\n                {\n                    var (sink, inner) = AsyncObserver.Catch(observer, handler);\n\n                    var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(subscription, inner);\n                });\n        }\n\n        public static IAsyncObservable<TSource> Catch<TSource>(this IAsyncObservable<TSource> first, IAsyncObservable<TSource> second)\n        {\n            if (first == null)\n                throw new ArgumentNullException(nameof(first));\n            if (second == null)\n                throw new ArgumentNullException(nameof(second));\n\n            return Create(\n                first,\n                second,\n                static async (first, second, observer) =>\n                {\n                    var (sink, inner) = AsyncObserver.Catch(observer, second);\n\n                    var subscription = await first.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(subscription, inner);\n                });\n        }\n\n        public static IAsyncObservable<TSource> Catch<TSource>(params IAsyncObservable<TSource>[] sources) => Catch((IEnumerable<IAsyncObservable<TSource>>)sources);\n\n        public static IAsyncObservable<TSource> Catch<TSource>(this IEnumerable<IAsyncObservable<TSource>> sources)\n        {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Catch.cs#L44-L80","documentation":"Catch(first, second) subscribes to 'first' and, if it fails, re-subscribes to 'second'. The extension method validates both arguments up front; passing a null 'second' means there is no fallback source, so System.Reactive.Async throws ArgumentNullException before any subscription happens.","triggerScenarios":"Calling the two-source overload Catch(first, second) with a null second observable, e.g. a factory method or dictionary lookup that returned null instead of a valid IAsyncObservable<TSource>.","commonSituations":"Conditional fallback chains where a secondary stream is only assigned when a feature is enabled, DI containers resolving the fallback as null, or caching/lookup code returning null for the retry source.","solutions":["Ensure the fallback observable is created before calling Catch (e.g. AsyncObservable.Empty<TSource>() instead of null)","Check the expression producing 'second' for a code path that returns null","Add a null check or ?? AsyncObservable.Empty<TSource>() at the call site"],"exampleFix":"// before\nvar result = primary.Catch(GetFallback()); // GetFallback() may return null\n// after\nvar fallback = GetFallback() ?? AsyncObservable.Empty<int>();\nvar result = primary.Catch(fallback);","handlingStrategy":"validation","validationCode":"if (first is null) throw new ArgumentNullException(nameof(first));\nif (second is null) throw new ArgumentNullException(nameof(second));","typeGuard":"bool IsValid<T>(IAsyncObservable<T> first, IAsyncObservable<T> second) => first != null && second != null;","tryCatchPattern":"try { var result = first.Catch(second); } catch (ArgumentNullException ex) { /* ex.ParamName == \"second\"; supply a real fallback */ }","preventionTips":["Never pass nullable observable variables directly; coalesce with AsyncObservable.Empty<T>()","Validate factory/lookup results for null before composing operators","Prefer explicit empty or throw fallbacks over null sentinels"],"tags":["argument-null","rx","catch-operator"],"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"}