{"record":{"id":"13159552b00ef08f","repo":"dotnet/reactive","slug":"func","errorCode":null,"errorMessage":"func","messagePattern":"func","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Scan.cs","lineNumber":71,"sourceCode":"                throw new ArgumentNullException(nameof(source));\n            if (func == null)\n                throw new ArgumentNullException(nameof(func));\n\n            return CreateAsyncObservable<TResult>.From(\n                source,\n                (func, seed),\n                static (source, state, observer) => source.SubscribeSafeAsync(AsyncObserver.Scan(observer, state.seed, state.func)));\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> Scan<TSource>(IAsyncObserver<TSource> observer, Func<TSource, TSource, TSource> func)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (func == null)\n                throw new ArgumentNullException(nameof(func));\n\n            var hasValue = false;\n            var value = default(TSource);\n\n            return Create<TSource>(\n                async x =>\n                {\n                    if (hasValue)\n                    {\n                        try\n                        {\n                            value = func(value, x);\n                        }\n                        catch (Exception ex)\n                        {\n                            await observer.OnErrorAsync(ex).ConfigureAwait(false);\n                            return;\n                        }","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Scan.cs#L53-L89","documentation":"AsyncObserver.Scan<TSource>(observer, Func<TSource,TSource,TSource>) throws ArgumentNullException (paramName \"func\") because the accumulator delegate was null. This observer-level factory requires a combining function to maintain the running value across OnNextAsync invocations.","triggerScenarios":"Calling AsyncObserver.Scan(observer, null) — a null Func<TSource,TSource,TSource> forwarded from a custom operator or a null variable that was meant to hold the lambda.","commonSituations":"Hand-written operators delegating to AsyncObserver.Scan with a delegate resolved too late; tests constructing observers directly; refactoring that split func acquisition from observer creation.","solutions":["Supply the accumulator: AsyncObserver.Scan(observer, (acc, x) => acc + x).","Ensure the delegate is assigned before the observer factory call.","Use the public source.Scan(func) operator so argument wiring is handled centrally."],"exampleFix":"// before\nvar obs = AsyncObserver.Scan(observer, (Func<int, int, int>)null); // throws\n\n// after\nvar obs = AsyncObserver.Scan(observer, (acc, x) => acc + x);","handlingStrategy":"validation","validationCode":"if (func is null) throw new InvalidOperationException(\"accumulator required by AsyncObserver.Scan\");\nvar obs = AsyncObserver.Scan(observer, func);","typeGuard":"static bool IsValidAccumulator<TSource>(Func<TSource, TSource, TSource>? f) => f is not null;","tryCatchPattern":"try { var obs = AsyncObserver.Scan(observer, f); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"func\") { throw new OperatorConfigurationException(\"null accumulator\", ex); }","preventionTips":["Assign accumulator delegates before building observers.","In tests, use real lambdas rather than null placeholders for internal APIs.","Centralize operator construction so delegate acquisition cannot lag observer creation."],"tags":["argument-null","observer","async-reactive","internal-api"],"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"}