{"record":{"id":"e44698c27f36fcbc","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-e44698","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/Catch.cs","lineNumber":24,"sourceCode":"\nnamespace System.Linq\n{\n    public static partial class EnumerableEx\n    {\n        /// <summary>\n        /// Creates a sequence that corresponds to the source sequence, concatenating it with the sequence resulting from\n        /// calling an exception handler function in case of an error.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <typeparam name=\"TException\">Exception type to catch.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"handler\">Handler to invoke when an exception of the specified type occurs.</param>\n        /// <returns>Source sequence, concatenated with an exception handler result sequence in case of an error.</returns>\n        public static IEnumerable<TSource> Catch<TSource, TException>(this IEnumerable<TSource> source, Func<TException, IEnumerable<TSource>> handler)\n            where TException : Exception\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (handler == null)\n                throw new ArgumentNullException(nameof(handler));\n\n            return CatchCore(source, handler);\n        }\n\n        /// <summary>\n        /// Creates a sequence by concatenating source sequences until a source sequence completes successfully.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <param name=\"sources\">Source sequences.</param>\n        /// <returns>Sequence that continues to concatenate source sequences while errors occur.</returns>\n        public static IEnumerable<TSource> Catch<TSource>(this IEnumerable<IEnumerable<TSource>> sources)\n        {\n            if (sources == null)\n                throw new ArgumentNullException(nameof(sources));\n\n            return CatchCore(sources);","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/Catch.cs#L6-L42","documentation":"The Catch operator overload Catch<TSource,TException>(source, handler) throws ArgumentNullException with parameter name 'source' when the source sequence is null. Ix.NET validates arguments eagerly so nulls are reported at the point of the call. The handler parameter must also be non-null or a separate error for 'handler' is thrown.","triggerScenarios":"Calling source.Catch<TException>(handler) where the receiver sequence is null, e.g. a method returned null instead of an empty sequence.","commonSituations":"Chaining operators on a repository method's result that can return null; using a nullable field directly as the source; interop with APIs that use null to mean 'no data'.","solutions":["Ensure the source is non-null; use Enumerable.Empty<TSource>() when there is no data.","Coalesce at the call site: (source ?? Enumerable.Empty<T>()).Catch(handler).","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 = possiblyNullSource.Catch<MyException>(ex => fallback);\n// after\nvar result = (possiblyNullSource ?? Enumerable.Empty<int>()).Catch<MyException>(ex => fallback);","handlingStrategy":"validation","validationCode":"if (source is null)\n    throw new ArgumentNullException(nameof(source));\n// or coalesce at the call site:\nvar result = (source ?? Enumerable.Empty<TSource>()).Catch(handler);","typeGuard":"static bool IsUsableSource<TSource>(IEnumerable<TSource> s) => s != null;","tryCatchPattern":"try\n{\n    var result = source.Catch<MyException>(handler);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\")\n{\n    var result = Enumerable.Empty<TSource>();\n}","preventionTips":["Never use nullable sequence fields directly as operator 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.","Check extension-method receivers for null before chaining operator pipelines."],"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"}