{"record":{"id":"ed4b2ffdd838f5db","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-observer-window","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'observer')","messagePattern":"Value cannot be null\\. \\(Parameter 'observer'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs","lineNumber":221,"sourceCode":"            var d = new SingleAssignmentAsyncDisposable();\n\n            var (sink, subscription) = await createObserverAsync(observer, d).ConfigureAwait(false);\n\n            var inner = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n            await d.AssignAsync(inner).ConfigureAwait(false);\n\n            return subscription;\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static (IAsyncObserver<TSource>, IAsyncDisposable) Window<TSource>(IAsyncObserver<IAsyncObservable<TSource>> observer, IAsyncDisposable subscription, int count) => Window(observer, subscription, count, count);\n\n        public static (IAsyncObserver<TSource>, IAsyncDisposable) Window<TSource>(IAsyncObserver<IAsyncObservable<TSource>> observer, IAsyncDisposable subscription, int count, int skip)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (subscription == null)\n                throw new ArgumentNullException(nameof(subscription));\n            if (count <= 0)\n                throw new ArgumentOutOfRangeException(nameof(count));\n            if (skip <= 0)\n                throw new ArgumentOutOfRangeException(nameof(skip));\n\n            var refCount = new RefCountAsyncDisposable(subscription);\n\n            var queue = new Queue<IAsyncSubject<TSource>>();\n            var n = 0;\n\n            return\n                (\n                    Create<TSource>\n                    (\n                        async x =>\n                        {","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs#L203-L239","documentation":"This ArgumentNullException is thrown by the internal static Window<TSource> helper (observer, subscription, count) when the downstream IAsyncObserver<IAsyncObservable<TSource>> is null. This helper implements the count-based Window operator's core; it validates the observer, subscription, count, and skip before wiring up the queue of async subjects. A null observer means the operator has nothing to push window observables to.","triggerScenarios":"Calling Window(observer, subscription, count) or Window(observer, subscription, count, skip) with a null observer argument — typically from custom operator plumbing or tests that pass null for the observer.","commonSituations":"Writing a custom async-Rx operator that composes Window's internals; unit tests exercising the helper with placeholder nulls; refactoring that dropped observer creation before the call.","solutions":["Pass a valid IAsyncObserver<IAsyncObservable<TSource>> (e.g. the observer supplied to your operator's SubscribeAsync).","If calling from a custom operator, forward the observer you received rather than constructing a null.","In tests, provide a stub/mock observer instead of null.","Guard your own code with ArgumentNullException.ThrowIfNull before delegating so the failure surfaces at your boundary."],"exampleFix":"// before\nvar (winObs, disp) = WindowOperators.Window<TSource>(null, subscription, 5);\n// after\nvar (winObs, disp) = WindowOperators.Window<TSource>(observer, subscription, 5);","handlingStrategy":"validation","validationCode":"if (observer is null) throw new ArgumentNullException(nameof(observer));","typeGuard":"bool IsValidObserver<TSource>(IAsyncObserver<IAsyncObservable<TSource>>? o) => o is not null;","tryCatchPattern":"try\n{\n    var (winObs, disp) = WindowOperators.Window<TSource>(observer, subscription, count);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\")\n{\n    throw new InvalidOperationException(\"Window helper requires a downstream observer.\", ex);\n}","preventionTips":["Always forward the observer received in SubscribeAsync into operator helpers.","In tests, use stub observers instead of null placeholders.","Add ArgumentNullException.ThrowIfNull at the top of custom operators."],"tags":["null-argument","argument-validation","async-rx","window-operator"],"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"}