{"record":{"id":"63e0607652efdbd7","repo":"dotnet/reactive","slug":"argumentnullexception-default-message-value-cannot-be-null-63e060","errorCode":null,"errorMessage":"ArgumentNullException (default message: Value cannot be null. (Parameter 'accumulator'))","messagePattern":"ArgumentNullException \\(default message: Value cannot be null\\. \\(Parameter 'accumulator'\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Single.cs","lineNumber":714,"sourceCode":"        /// For aggregation behavior with no intermediate results, see <see cref=\"Observable.Aggregate{TSource, Accumulate}\"/>.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TAccumulate\">The type of the result of the aggregation.</typeparam>\n        /// <param name=\"source\">An observable sequence to accumulate over.</param>\n        /// <param name=\"seed\">The initial accumulator value.</param>\n        /// <param name=\"accumulator\">An accumulator function to be invoked on each element.</param>\n        /// <returns>An observable sequence containing the accumulated values.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"accumulator\"/> is null.</exception>\n        public static IObservable<TAccumulate> Scan<TSource, TAccumulate>(this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (accumulator == null)\n            {\n                throw new ArgumentNullException(nameof(accumulator));\n            }\n\n            return s_impl.Scan(source, seed, accumulator);\n        }\n\n        /// <summary>\n        /// Applies an accumulator function over an observable sequence and returns each intermediate result.\n        /// For aggregation behavior with no intermediate results, see <see cref=\"Observable.Aggregate{TSource}\"/>.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence and the result of the aggregation.</typeparam>\n        /// <param name=\"source\">An observable sequence to accumulate over.</param>\n        /// <param name=\"accumulator\">An accumulator function to be invoked on each element.</param>\n        /// <returns>An observable sequence containing the accumulated values.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"accumulator\"/> is null.</exception>\n        public static IObservable<TSource> Scan<TSource>(this IObservable<TSource> source, Func<TSource, TSource, TSource> accumulator)\n        {\n            if (source == null)\n            {","sourceCodeStart":696,"sourceCodeEnd":732,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Single.cs#L696-L732","documentation":"Scan throws ArgumentNullException when the `accumulator` function is null. The accumulator is required to fold each element into the running value; without it the operator cannot be constructed, so Rx throws immediately.","triggerScenarios":"Calling Scan(source, seed, accumulator) with a null accumulator delegate (line 714 check).","commonSituations":"Selecting an aggregation function from a dictionary/registry of reducers that lacks the requested key; passing a method group on a null object obtained via reflection.","solutions":["Pass a valid Func<TAccumulate, TSource, TAccumulate>.","Fix the reducer lookup/factory returning null.","Provide a default accumulator for the configured aggregation mode."],"exampleFix":"// before\nvar reducer = _reducers.TryGetValue(kind, out var r) ? r : null;\nvar sum = source.Scan(0, reducer);\n// after\nvar reducer = _reducers.TryGetValue(kind, out var r) ? r : (acc, x) => acc + x;\nvar sum = source.Scan(0, reducer);","handlingStrategy":"validation","validationCode":"if (accumulator is null) throw new ArgumentNullException(nameof(accumulator));\nvar sum = source.Scan(seed, accumulator);","typeGuard":"bool IsValidAccumulator<TAcc,TSource>(Func<TAcc,TSource,TAcc>? f) => f is not null;","tryCatchPattern":"try { sum = source.Scan(seed, acc); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"accumulator\") { sum = source.Scan(seed, (a, _) => a); }","preventionTips":["Fail fast in reducer registries (throw on missing key, never return null).","Use pattern matching or switch expressions that guarantee a non-null fallback.","Test every aggregation-mode configuration path in unit tests."],"tags":["rx","null-check","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"}