{"record":{"id":"c3f84e5c09ebd79e","repo":"dotnet/reactive","slug":"argumentnullexception-default-message-value-cannot-be-null","errorCode":null,"errorMessage":"ArgumentNullException (default message: Value cannot be null. (Parameter 'source'))","messagePattern":"ArgumentNullException \\(default message: Value cannot be null\\. \\(Parameter 'source'\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Single.cs","lineNumber":709,"sourceCode":"\n        #region + Scan +\n\n        /// <summary>\n        /// Applies an accumulator function over an observable sequence and returns each intermediate result. The specified seed value is used as the initial accumulator value.\n        /// 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>","sourceCodeStart":691,"sourceCodeEnd":727,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Single.cs#L691-L727","documentation":"Scan(source, seed, accumulator) throws ArgumentNullException when the source sequence is null. Rx operators validate arguments synchronously at composition time so bad inputs surface at the call site, not mid-stream.","triggerScenarios":"Calling Observable.Scan(source, seed, accumulator) with a null `source` (line 709 check, before the accumulator check).","commonSituations":"Scan chained onto a nullable result of a repository/API call returning IObservable<T> or null; DI wiring where a sequence dependency is unregistered.","solutions":["Guarantee a non-null source before calling Scan.","Replace null with an empty or default sequence when absence is valid.","Fix the upstream factory that returned null.","Wrap the composition in argument validation with a clearer domain message."],"exampleFix":"// before\nvar running = (GetStream() as IObservable<int>).Scan(0, (acc, x) => acc + x);\n// after\nvar src = GetStream() ?? Observable.Empty<int>();\nvar running = src.Scan(0, (acc, x) => acc + x);","handlingStrategy":"validation","validationCode":"if (source is null) throw new ArgumentNullException(nameof(source));\nvar running = source.Scan(seed, (acc, x) => acc + x);","typeGuard":"bool HasStream<TSource>(IObservable<TSource>? s) => s is not null;","tryCatchPattern":"try { result = src.Scan(seed, acc); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { result = Observable.Empty<TAccumulate>(); }","preventionTips":["Return Observable.Return/Empty instead of null from sequence providers.","Coalesce nullable sources at composition time.","Run composition inside a checked factory that validates inputs once."],"tags":["rx","null-check","scan"],"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"}