{"record":{"id":"a347d30f25a8212c","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-windowclosingselector","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'windowClosingSelector')","messagePattern":"Value cannot be null\\. \\(Parameter 'windowClosingSelector'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs","lineNumber":169,"sourceCode":"\n                    var sourceSubscription = await source.SubscribeSafeAsync(sourceObserver).ConfigureAwait(false);\n                    await d.AddAsync(sourceSubscription).ConfigureAwait(false);\n\n                    var boundariesSubscription = await windowBoundaries.SubscribeSafeAsync(boundariesObserver).ConfigureAwait(false);\n                    await d.AddAsync(boundariesSubscription).ConfigureAwait(false);\n\n                    return subscription;\n                });\n        }\n\n        // REVIEW: This overload is inherited from Rx but arguably a bit esoteric as it doesn't provide context to the closing selector.\n\n        public static IAsyncObservable<IAsyncObservable<TSource>> Window<TSource, TWindowClosing>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TWindowClosing>> windowClosingSelector)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (windowClosingSelector == null)\n                throw new ArgumentNullException(nameof(windowClosingSelector));\n\n            return CreateAsyncObservable<IAsyncObservable<TSource>>.From(\n                source,\n                windowClosingSelector,\n                static async (source, windowClosingSelector, observer) =>\n                {\n                    var d = new CompositeAsyncDisposable();\n\n                    var (sourceObserver, closingSubscription, subscription) = await AsyncObserver.Window<TSource, TWindowClosing>(observer, windowClosingSelector, d).ConfigureAwait(false);\n\n                    await d.AddAsync(closingSubscription).ConfigureAwait(false);\n\n                    var sourceSubscription = await source.SubscribeSafeAsync(sourceObserver).ConfigureAwait(false);\n                    await d.AddAsync(sourceSubscription).ConfigureAwait(false);\n\n                    return subscription;\n                });\n        }","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs#L151-L187","documentation":"This ArgumentNullException is thrown by the Window<TSource,TWindowClosing> operator when the windowClosingSelector delegate is null. The selector is required to create each new window's closing observable, so the operator rejects a null selector immediately at call time. No subscription ever happens in this case.","triggerScenarios":"Calling source.Window(null) on the parameterless overload, e.g. a Func<IAsyncObservable<TWindowClosing>> variable that was never assigned, or a conditional expression that resolved to null.","commonSituations":"Passing a method group that doesn't match an overload and binding to null instead; storing the selector in a nullable field initialized after use; refactoring that removed the lambda but left the call.","solutions":["Pass a non-null window-closing selector, e.g. () => AsyncObservable.Interval(TimeSpan.FromSeconds(5)).","If the selector comes from a variable, initialize it before calling Window.","Throw your own descriptive exception at the call site if the selector may legitimately be absent.","Choose a different Window overload (count-based or time-based) if a closing selector isn't actually needed."],"exampleFix":"// before\nFunc<IAsyncObservable<long>> closing = null;\nvar windows = source.Window(closing);\n// after\nvar windows = source.Window(() => AsyncObservable.Interval(TimeSpan.FromSeconds(5)));","handlingStrategy":"validation","validationCode":"if (windowClosingSelector is null) throw new ArgumentNullException(nameof(windowClosingSelector));","typeGuard":"bool IsValidSelector<TW>(Func<IAsyncObservable<TW>>? sel) => sel is not null;","tryCatchPattern":"try\n{\n    var windows = source.Window(closingSelector);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"windowClosingSelector\")\n{\n    closingSelector = () => AsyncObservable.Interval(TimeSpan.FromSeconds(5));\n}","preventionTips":["Pass method groups or lambdas directly instead of nullable delegate fields.","Initialize delegate fields with a default selector at declaration time.","Prefer the count/time-based Window overloads when no closing selector is needed."],"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"}