{"record":{"id":"a265d82641334919","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-merge","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'merge')","messagePattern":"Value cannot be null\\. \\(Parameter 'merge'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Blocking.cs","lineNumber":59,"sourceCode":"        /// <param name=\"newCollector\">Factory to create a new collector object.</param>\n        /// <param name=\"merge\">Merges a sequence element with the current collector.</param>\n        /// <returns>The enumerable sequence that returns collected/aggregated elements from the source sequence upon each iteration.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"newCollector\"/> or <paramref name=\"merge\"/> is null.</exception>\n        public static IEnumerable<TResult> Collect<TSource, TResult>(this IObservable<TSource> source, Func<TResult> newCollector, Func<TResult, TSource, TResult> merge)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (newCollector == null)\n            {\n                throw new ArgumentNullException(nameof(newCollector));\n            }\n\n            if (merge == null)\n            {\n                throw new ArgumentNullException(nameof(merge));\n            }\n\n            return s_impl.Collect(source, newCollector, merge);\n        }\n\n        /// <summary>\n        /// Produces an enumerable sequence that returns elements collected/aggregated from the source sequence between consecutive iterations.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements produced by the merge operation during collection.</typeparam>\n        /// <param name=\"source\">Source observable sequence.</param>\n        /// <param name=\"getInitialCollector\">Factory to create the initial collector object.</param>\n        /// <param name=\"merge\">Merges a sequence element with the current collector.</param>\n        /// <param name=\"getNewCollector\">Factory to replace the current collector by a new collector.</param>\n        /// <returns>The enumerable sequence that returns collected/aggregated elements from the source sequence upon each iteration.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"getInitialCollector\"/> or <paramref name=\"merge\"/> or <paramref name=\"getNewCollector\"/> is null.</exception>\n        public static IEnumerable<TResult> Collect<TSource, TResult>(this IObservable<TSource> source, Func<TResult> getInitialCollector, Func<TResult, TSource, TResult> merge, Func<TResult, TResult> getNewCollector)\n        {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Blocking.cs#L41-L77","documentation":"System.ArgumentNullException thrown by Observable.Collect(source, newCollector, merge) when the merge aggregation delegate is null. Rx validates arguments in order, so this only occurs when both source and newCollector are valid but the combining function is missing.","triggerScenarios":"Calling Collect(source, () => seed, null) — usually a misordered argument list, a null Func field, or a conditional that produced no combiner.","commonSituations":"Refactoring that dropped the merge lambda; passing a method group on a null object; generic wrappers that forward a possibly-null delegate.","solutions":["Provide a non-null merge Func<TResult, TSource, TResult>, e.g. (acc, x) => acc + x.","Reorder arguments if the merge lambda was accidentally placed in the wrong position.","Guard nullable delegate fields before the call."],"exampleFix":"// before\nvar result = source.Collect(() => 0, mergeFn); // mergeFn == null\n// after\nvar result = source.Collect(() => 0, (acc, x) => acc + x);","handlingStrategy":"validation","validationCode":"if (merge is null) throw new InvalidOperationException(\"Collect requires a non-null merge function\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var result = source.Collect(() => seed, merge);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"merge\")\n{\n    // supply or repair the aggregation function\n}","preventionTips":["Write merge lambdas inline at the call site instead of via nullable variables.","Double-check argument order when overloads differ by delegate count.","Unit-test aggregation pipelines with all delegates supplied."],"tags":["null-argument","rx","delegate"],"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"}