{"record":{"id":"3e74129a9b71a591","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-second-3e7412","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'second')","messagePattern":"Value cannot be null\\. \\(Parameter 'second'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/Catch.cs","lineNumber":71,"sourceCode":"            if (sources == null)\n                throw new ArgumentNullException(nameof(sources));\n\n            return CatchCore(sources);\n        }\n\n        /// <summary>\n        /// Creates a sequence that returns the elements of the first sequence, switching to the second in case of an error.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <param name=\"first\">First sequence.</param>\n        /// <param name=\"second\">Second sequence, concatenated to the result in case the first sequence completes exceptionally.</param>\n        /// <returns>The first sequence, followed by the second sequence in case an error is produced.</returns>\n        public static IEnumerable<TSource> Catch<TSource>(this IEnumerable<TSource> first, IEnumerable<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 CatchCore(new[] { first, second });\n        }\n\n        private static IEnumerable<TSource> CatchCore<TSource, TException>(IEnumerable<TSource> source, Func<TException, IEnumerable<TSource>> handler)\n            where TException : Exception\n        {\n            var err = default(IEnumerable<TSource>);\n\n            using (var e = source.GetEnumerator())\n            {\n                while (true)\n                {\n                    TSource c;\n\n                    try\n                    {\n                        if (!e.MoveNext())","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/Catch.cs#L53-L89","documentation":"The two-sequence overload Catch<TSource>(first, second) throws ArgumentNullException with parameter name 'second' when the fallback sequence is null. The second sequence is concatenated when the first fails, so it must be non-null; validation happens eagerly at call time.","triggerScenarios":"Calling first.Catch(second) with null as the second (fallback) sequence.","commonSituations":"A fallback obtained from a lookup or factory that returned null; assuming null means 'empty fallback' instead of Enumerable.Empty<T>(); refactoring that dropped the fallback assignment.","solutions":["Pass Enumerable.Empty<TSource>() for an empty fallback instead of null.","Check why the fallback expression evaluated to null and fix the producer.","Coalesce: first.Catch(second ?? Enumerable.Empty<T>()).","Enable nullable reference types to catch it at compile time."],"exampleFix":"// before\nvar result = primary.Catch((IEnumerable<int>)null);\n// after\nvar result = primary.Catch(Enumerable.Empty<int>());","handlingStrategy":"validation","validationCode":"if (second is null)\n    throw new ArgumentNullException(nameof(second));\n// or coalesce:\nsecond ??= Enumerable.Empty<TSource>();","typeGuard":"static bool HasFallback<TSource>(IEnumerable<TSource> s) => s != null;","tryCatchPattern":"try\n{\n    var result = first.Catch(second);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"second\")\n{\n    var result = first.Catch(Enumerable.Empty<TSource>());\n}","preventionTips":["Express an empty fallback with Enumerable.Empty<T>(), never null.","Coalesce nullable fallbacks with ?? Enumerable.Empty<T>().","Ensure fallback producers (lookups, factories) never return null.","Enable nullable reference types to catch null arguments at compile time."],"tags":["csharp","null-argument","linq","ix-net","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"}