{"record":{"id":"999c49c2fe005afd","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-getinitialcollector","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'getInitialCollector')","messagePattern":"Value cannot be null\\. \\(Parameter 'getInitialCollector'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Blocking.cs","lineNumber":85,"sourceCode":"        /// </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        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (getInitialCollector == null)\n            {\n                throw new ArgumentNullException(nameof(getInitialCollector));\n            }\n\n            if (merge == null)\n            {\n                throw new ArgumentNullException(nameof(merge));\n            }\n\n            if (getNewCollector == null)\n            {\n                throw new ArgumentNullException(nameof(getNewCollector));\n            }\n\n            return s_impl.Collect(source, getInitialCollector, merge, getNewCollector);\n        }\n\n        #endregion\n\n        #region + First +","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Blocking.cs#L67-L103","documentation":"System.ArgumentNullException thrown by the 4-argument Observable.Collect overload when getInitialCollector is null. This is the seed-factory delegate producing the initial accumulator; Rx rejects it before the enumerable is returned.","triggerScenarios":"Calling Collect(source, null, merge, getNewCollector) — commonly a misordered call, an uninitialized Func field, or a factory method returning null.","commonSituations":"Constructing aggregation pipelines from configuration where the seed expression failed to bind; refactoring that swapped argument positions between the 3-arg and 4-arg overloads.","solutions":["Supply a valid Func<TResult> seed factory, e.g. () => 0.","Check argument order — the overload overloads look similar; ensure the seed lambda is the 2nd argument.","Initialize delegate fields/properties before use."],"exampleFix":"// before\nvar result = source.Collect(seedFactory, (a, x) => a + x, _ => 0); // seedFactory == null\n// after\nvar result = source.Collect(() => 0, (a, x) => a + x, _ => 0);","handlingStrategy":"validation","validationCode":"if (getInitialCollector is null) throw new InvalidOperationException(\"Collect requires a non-null initial collector factory\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var result = source.Collect(getInitialCollector, merge, getNewCollector);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"getInitialCollector\")\n{\n    // fall back to a default seed\n}","preventionTips":["Mind overload differences: the 4-arg Collect needs a seed factory as the 2nd argument.","Avoid nullable Func fields for seeds; inline the lambda.","Add argument-order-sensitive unit tests for aggregation helpers."],"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"}