{"record":{"id":"f85fd2fa36b275a6","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-first-f85fd2","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'first')","messagePattern":"Value cannot be null\\. \\(Parameter 'first'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/Catch.cs","lineNumber":69,"sourceCode":"        public static IEnumerable<TSource> Catch<TSource>(params IEnumerable<TSource>[] sources)\n        {\n            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","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/Catch.cs#L51-L87","documentation":"The two-sequence overload Catch<TSource>(first, second) throws ArgumentNullException with parameter name 'first' when the first (extension receiver) sequence is null. The operator concatenates first with second as an error fallback, so both sequences must be non-null; validation happens eagerly at call time.","triggerScenarios":"Calling first.Catch(second) where the first sequence is null, e.g. the result of a prior operation that can return null.","commonSituations":"A data-access method returning null instead of an empty sequence; an optional field used directly as the primary sequence; pipeline wiring where an earlier operator produced null.","solutions":["Ensure the first sequence is non-null; use Enumerable.Empty<TSource>() if there is no data.","Coalesce at the call site: (first ?? Enumerable.Empty<T>()).Catch(second).","Fix the upstream method to return an empty sequence rather than null.","Enable nullable reference types so the compiler warns before the call."],"exampleFix":"// before\nvar result = ((IEnumerable<int>)null).Catch(fallback);\n// after\nvar result = (first ?? Enumerable.Empty<int>()).Catch(fallback);","handlingStrategy":"validation","validationCode":"if (first is null)\n    throw new ArgumentNullException(nameof(first));\n// or coalesce at the call site:\nvar result = (first ?? Enumerable.Empty<TSource>()).Catch(second);","typeGuard":"static bool IsUsableSource<TSource>(IEnumerable<TSource> s) => s != null;","tryCatchPattern":"try\n{\n    var result = first.Catch(second);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"first\")\n{\n    var result = second;\n}","preventionTips":["Never use nullable sequence fields directly as extension receivers; coalesce with ?? Enumerable.Empty<T>().","Make upstream APIs return empty sequences instead of null.","Enable nullable reference types to catch null receivers at compile time.","Validate pipeline inputs before chaining operators."],"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"}