dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'accumulator')
Error message
Value cannot be null. (Parameter 'accumulator')
What it means
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.
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
Example fix
// before var result = source.Scan(seed, accumulator); // accumulator may be null // after var result = source.Scan(seed, accumulator ?? ((acc, x) => acc));
Defensive patterns
Strategy: validation
Validate before calling
if (accumulator is null) throw new ArgumentNullException(nameof(accumulator)); var result = source.Scan(seed, accumulator);
Try / catch
try { var r = source.Scan(seed, accumulator); }
catch (ArgumentNullException ex) when (ex.ParamName == "accumulator") { /* substitute default accumulator */ } Prevention
- Initialize delegate fields at construction
- Provide default accumulators for dynamic strategy selection
- Fail fast where delegates are configured
When it happens
Trigger: 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.
Common situations: Strategy/accumulator functions selected dynamically where a branch yields null; delegates stored in fields that were never assigned.
Related errors
- Value cannot be null. (Parameter 'handler')
- Value cannot be null. (Parameter 'defaultSource')
- Value cannot be null. (Parameter 'source')
- Value cannot be null. (Parameter 'sources')
- Value cannot be null. (Parameter 'first')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/dd9f99030128585c.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/System.Interactive/System/Linq/Operators/Scan.cs:28
{
/// <summary>
/// Generates a sequence of accumulated values by scanning the source sequence and applying an accumulator function.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <typeparam name="TAccumulate">Accumulation type.</typeparam>
/// <param name="source">Source sequence.</param>
/// <param name="seed">Accumulator seed value.</param>
/// <param name="accumulator">
/// Accumulation function to apply to the current accumulation value and each element of the
/// sequence.
/// </param>
/// <returns>Sequence with all intermediate accumulation values resulting from scanning the sequence.</returns>
public static IEnumerable<TAccumulate> Scan<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (accumulator == null)
throw new ArgumentNullException(nameof(accumulator));
return ScanCore(source, seed, accumulator);
}
/// <summary>
/// Generates a sequence of accumulated values by scanning the source sequence and applying an accumulator function.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="source">Source sequence.</param>
/// <param name="accumulator">
/// Accumulation function to apply to the current accumulation value and each element of the
/// sequence.
/// </param>
/// <returns>Sequence with all intermediate accumulation values resulting from scanning the sequence.</returns>
public static IEnumerable<TSource> Scan<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TSource> accumulator)
{
if (source == null)
throw new ArgumentNullException(nameof(source));View on GitHub (pinned to 94b5d5ab91)