{"record":{"id":"127b9f1fe8cf12ae","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-subscription-window","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'subscription')","messagePattern":"Value cannot be null\\. \\(Parameter 'subscription'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs","lineNumber":223,"sourceCode":"            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                        {\n                            foreach (var window in queue)\n                            {","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs#L205-L241","documentation":"This ArgumentNullException is thrown by the count-based Window helper when the subscription IAsyncDisposable is null. The subscription represents the upstream disposable and is wrapped in a RefCountAsyncDisposable, so a null value cannot be accepted. It fails fast at the call, before any windows are created.","triggerScenarios":"Calling Window(observer, null, count) or Window(observer, null, count, skip) — usually when wiring a custom operator and the upstream disposable hasn't been created yet.","commonSituations":"Custom operator implementations where the CompositeAsyncDisposable is created after the helper call; test harnesses passing null disposables; reordering refactors in operator plumbing.","solutions":["Create and pass a real disposable, e.g. new CompositeAsyncDisposable(), before calling Window.","Pass the disposable you obtained from the upstream SubscribeAsync call.","Use AsyncDisposable.Nop / an empty composite if no upstream subscription exists yet.","Add a null check in your wrapper so the error points at your call site."],"exampleFix":"// before\nvar (winObs, disp) = WindowOperators.Window<TSource>(observer, null, 5);\n// after\nvar d = new CompositeAsyncDisposable();\nvar (winObs, disp) = WindowOperators.Window<TSource>(observer, d, 5);","handlingStrategy":"validation","validationCode":"if (subscription is null) throw new ArgumentNullException(nameof(subscription));\n// or: subscription ??= AsyncDisposable.Nop;","typeGuard":"bool IsValidDisposable(IAsyncDisposable? d) => d is not null;","tryCatchPattern":"try\n{\n    var (winObs, disp) = WindowOperators.Window<TSource>(observer, subscription, count);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"subscription\")\n{\n    subscription = new CompositeAsyncDisposable();\n}","preventionTips":["Create the upstream/CompositeAsyncDisposable before calling operator helpers.","Forward the disposable from SubscribeAsync results directly.","Use AsyncDisposable.Nop as an explicit 'no resource' value instead of null."],"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"}