{"record":{"id":"b5c66326130ec35c","repo":"dotnet/reactive","slug":"observer-scan","errorCode":null,"errorMessage":"observer","messagePattern":"observer","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Scan.cs","lineNumber":107,"sourceCode":"                        }\n                    }\n                    else\n                    {\n                        value = x;\n                        hasValue = true;\n                    }\n\n                    await observer.OnNextAsync(value).ConfigureAwait(false);\n                },\n                observer.OnErrorAsync,\n                observer.OnCompletedAsync\n            );\n        }\n\n        public static IAsyncObserver<TSource> Scan<TSource>(IAsyncObserver<TSource> observer, Func<TSource, TSource, ValueTask<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 = await func(value, x).ConfigureAwait(false);\n                        }\n                        catch (Exception ex)\n                        {\n                            await observer.OnErrorAsync(ex).ConfigureAwait(false);","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Scan.cs#L89-L125","documentation":"AsyncObserver.Scan<TSource>(observer, Func<TSource,TSource,ValueTask<TSource>>) — the async-accumulator observer factory backing the async Scan overload — throws ArgumentNullException because the observer argument was null. The wrapper needs the downstream observer to forward accumulated values and completion signals.","triggerScenarios":"Calling AsyncObserver.Scan(null, asyncFunc) through internal or custom operator code where the downstream IAsyncObserver<TSource> was null — typically a subscription path that failed to construct or pass the observer.","commonSituations":"Custom subscription implementations with nullable observer fields; composing observer chains where an earlier stage dropped the observer; direct internal-API testing.","solutions":["Pass a constructed downstream observer as the first argument.","Audit the custom subscription path to ensure the observer is created before AsyncObserver.Scan is invoked.","Route through the public source.Scan(asyncFunc) API to avoid manual observer wiring."],"exampleFix":"// before\nvar obs = AsyncObserver.Scan<int>((IAsyncObserver<int>)null, async (a, b) => a + b); // throws\n\n// after\nvar obs = AsyncObserver.Scan(observer, async (a, b) => a + b);","handlingStrategy":"validation","validationCode":"if (observer is null) throw new InvalidOperationException(\"downstream observer required by AsyncObserver.Scan (async)\");\nvar obs = AsyncObserver.Scan(observer, asyncFunc);","typeGuard":"static bool HasObserver<TSource>(IAsyncObserver<TSource>? o) => o is not null;","tryCatchPattern":"try { var obs = AsyncObserver.Scan(observer, f); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\") { log.LogError(\"null observer in async scan chain\"); throw; }","preventionTips":["Ensure subscription code always instantiates and forwards the downstream observer.","Avoid nullable observer parameters in custom operator signatures.","Prefer public Scan overloads which construct and pass the observer internally."],"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"}