{"record":{"id":"dd9f99030128585c","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-accumulator","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'accumulator')","messagePattern":"Value cannot be null\\. \\(Parameter 'accumulator'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/Scan.cs","lineNumber":28,"sourceCode":"    {\n        /// <summary>\n        /// Generates a sequence of accumulated values by scanning the source sequence and applying an accumulator function.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <typeparam name=\"TAccumulate\">Accumulation type.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"seed\">Accumulator seed value.</param>\n        /// <param name=\"accumulator\">\n        /// Accumulation function to apply to the current accumulation value and each element of the\n        /// sequence.\n        /// </param>\n        /// <returns>Sequence with all intermediate accumulation values resulting from scanning the sequence.</returns>\n        public static IEnumerable<TAccumulate> Scan<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (accumulator == null)\n                throw new ArgumentNullException(nameof(accumulator));\n\n            return ScanCore(source, seed, accumulator);\n        }\n\n        /// <summary>\n        /// Generates a sequence of accumulated values by scanning the source sequence and applying an accumulator function.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"accumulator\">\n        /// Accumulation function to apply to the current accumulation value and each element of the\n        /// sequence.\n        /// </param>\n        /// <returns>Sequence with all intermediate accumulation values resulting from scanning the sequence.</returns>\n        public static IEnumerable<TSource> Scan<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TSource> accumulator)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/Scan.cs#L10-L46","documentation":"Scan(source, seed, accumulator) requires a non-null accumulator function; passing null throws ArgumentNullException eagerly at call time. The accumulator is needed for every element, so the operator cannot proceed without it.","triggerScenarios":"Calling Scan with a null Func<TAccumulate, TSource, TAccumulate>, e.g. a delegate resolved from DI, a conditional expression, or a variable assigned only on some code path.","commonSituations":"Strategy/accumulator functions selected dynamically where a branch yields null; delegates stored in fields that were never assigned.","solutions":["Ensure the accumulator delegate is assigned before calling Scan","Provide a default accumulator as fallback","Assert delegate non-null early (e.g. in the configuring code) to fail fast near the cause"],"exampleFix":"// before\nvar result = source.Scan(seed, accumulator); // accumulator may be null\n// after\nvar result = source.Scan(seed, accumulator ?? ((acc, x) => acc));","handlingStrategy":"validation","validationCode":"if (accumulator is null) throw new ArgumentNullException(nameof(accumulator));\nvar result = source.Scan(seed, accumulator);","typeGuard":null,"tryCatchPattern":"try { var r = source.Scan(seed, accumulator); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"accumulator\") { /* substitute default accumulator */ }","preventionTips":["Initialize delegate fields at construction","Provide default accumulators for dynamic strategy selection","Fail fast where delegates are configured"],"tags":["csharp","linq","null-argument","delegate","ix-net"],"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"}