{"record":{"id":"7decd879027e9871","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-window","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs","lineNumber":139,"sourceCode":"            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (timeSpan < TimeSpan.Zero)\n                throw new ArgumentOutOfRangeException(nameof(timeSpan));\n            if (count <= 0)\n                throw new ArgumentOutOfRangeException(nameof(count));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return CreateAsyncObservable<IAsyncObservable<TSource>>.From(\n                source,\n                (timeSpan, count, scheduler),\n                static (source, state, observer) => WindowAsyncCore(source, observer, (o, d) => AsyncObserver.Window(o, d, state.timeSpan, state.count, state.scheduler)));\n        }\n\n        public static IAsyncObservable<IAsyncObservable<TSource>> Window<TSource, TWindowBoundary>(this IAsyncObservable<TSource> source, IAsyncObservable<TWindowBoundary> windowBoundaries)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (windowBoundaries == null)\n                throw new ArgumentNullException(nameof(windowBoundaries));\n\n            return CreateAsyncObservable<IAsyncObservable<TSource>>.From(\n                source,\n                windowBoundaries,\n                static async (source, windowBoundaries, observer) =>\n                {\n                    var d = new CompositeAsyncDisposable();\n\n                    var (sourceObserver, boundariesObserver, subscription) = await AsyncObserver.Window<TSource, TWindowBoundary>(observer, d).ConfigureAwait(false);\n\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","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs#L121-L157","documentation":"The Window(source, windowBoundaries) overload throws ArgumentNullException when the source observable is null (runtime message names parameter 'source'). Both the source and the boundary observable are validated synchronously; this guard covers the source.","triggerScenarios":"Calling source.Window(windowBoundaries) where source is null — usually an observable factory returning null on some code path, or an uninitialized field.","commonSituations":"Pipelines assembled from nullable steps; a helper returning IAsyncObservable<T> that can return null instead of an empty sequence; refactoring that removed an initialization.","solutions":["Ensure the source is non-null before invoking Window.","Have producers return AsyncObservable.Empty<T>() rather than null.","Add a ThrowIfNull guard at the pipeline construction point."],"exampleFix":"// before\nvar windows = BuildSource()?.Window(boundaries);\n// after\nvar src = BuildSource() ?? AsyncObservable.Empty<Event>();\nvar windows = src.Window(boundaries);","handlingStrategy":"validation","validationCode":"if (source is null) throw new ArgumentNullException(nameof(source));\nvar windows = source.Window(windowBoundaries);","typeGuard":"static bool IsSourceValid<TSource, B>(IAsyncObservable<TSource>? source, IAsyncObservable<B>? boundaries) => source is not null && boundaries is not null;","tryCatchPattern":"try { var windows = source.Window(boundaries); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* rebuild source and retry */ }","preventionTips":["Guard entire pipelines at construction with null checks on every observable input","Return empty observables instead of null from helper methods","Use nullable reference type warnings as build blockers"],"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"}