{"record":{"id":"6d2687331416b294","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-getnewcollector","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'getNewCollector')","messagePattern":"Value cannot be null\\. \\(Parameter 'getNewCollector'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Blocking.cs","lineNumber":95,"sourceCode":"        {\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 +\n\n        /// <summary>\n        /// Returns the first element of an observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source observable sequence.</param>\n        /// <returns>The first element in the observable sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        /// <exception cref=\"InvalidOperationException\">The source sequence is empty.</exception>\n        /// <seealso cref=\"Observable.FirstAsync{TSource}(IObservable{TSource})\"/>","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Blocking.cs#L77-L113","documentation":"System.ArgumentNullException thrown by the 4-argument Observable.Collect overload when getNewCollector is null. This delegate re-arms the collector after each emitted value; it is the last argument validated.","triggerScenarios":"Calling Collect(source, seed, merge, null) — often because the caller thought the 4th argument was optional or copied the 3-arg call shape and appended null.","commonSituations":"Porting code from the 3-argument Collect overload; wrappers that only sometimes supply a renewal function; reflection-based invocation with a missing argument.","solutions":["Supply a valid Func<TResult, TResult> renewal delegate, e.g. acc => acc (identity) if no reset is needed.","If no renewal behavior is required, use the 3-argument Collect overload instead of passing null.","Audit wrapper methods that forward optional delegates."],"exampleFix":"// before\nvar result = source.Collect(() => 0, (a, x) => a + x, null);\n// after\nvar result = source.Collect(() => 0, (a, x) => a + x, acc => acc);","handlingStrategy":"validation","validationCode":"if (getNewCollector is null) throw new InvalidOperationException(\"Collect requires a non-null renewal function\");\n// if no reset is needed, pass the identity function:\nvar renew = getNewCollector ?? (acc => acc);","typeGuard":null,"tryCatchPattern":"try\n{\n    var result = source.Collect(seed, merge, getNewCollector);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"getNewCollector\")\n{\n    // switch to the 3-arg Collect overload or supply identity renewal\n}","preventionTips":["If no renewal logic is required, use the 3-argument Collect overload instead of passing null.","Default optional delegates to identity functions rather than null.","Document required delegates in wrapper APIs."],"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-23T08:17:48.524Z"}