{"record":{"id":"e9e706af41efaf7a","repo":"dotnet/reactive","slug":"argumentnullexception-window","errorCode":null,"errorMessage":"ArgumentNullException","messagePattern":"ArgumentNullException","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs","lineNumber":19,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Collections.Generic;\nusing System.Reactive.Concurrency;\nusing System.Reactive.Disposables;\nusing System.Reactive.Subjects;\nusing System.Threading;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<IAsyncObservable<TSource>> Window<TSource>(this IAsyncObservable<TSource> source, int count)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (count <= 0)\n                throw new ArgumentOutOfRangeException(nameof(count));\n\n            return CreateAsyncObservable<IAsyncObservable<TSource>>.From(\n                source,\n                count,\n                static (source, count, observer) => WindowCore(source, observer, (o, d) => AsyncObserver.Window(o, d, count)));\n        }\n\n        public static IAsyncObservable<IAsyncObservable<TSource>> Window<TSource>(this IAsyncObservable<TSource> source, int count, int skip)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (count <= 0)\n                throw new ArgumentOutOfRangeException(nameof(count));\n            if (skip <= 0)\n                throw new ArgumentOutOfRangeException(nameof(skip));\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs#L1-L37","documentation":"Window<TSource>(source, count) splits the source into windows of at most count elements; the library throws ArgumentNullException when the source is null. This eager check is standard across AsyncRx operators so misuse is caught at composition time, not at subscription.","triggerScenarios":"Calling source.Window(count) via extension syntax with a null receiver, or AsyncObservable.Window(null, 5).","commonSituations":"Chaining off a query result that came back null; a nullable source variable not checked before composing the pipeline; source produced by an external factory with a null result.","solutions":["Check that the receiver/source is non-null before calling Window.","Replace a null source with AsyncObservable.Empty<TSource>() when absence is acceptable.","Move the null check upstream to whoever produces the source.","Use the null-forgiving/nullable-flow analysis (enable NRT warnings) so null sources are caught at compile time."],"exampleFix":"// before\nvar windows = maybeSource.Window(3); // maybeSource is null\n// after\nvar windows = (maybeSource ?? AsyncObservable.Empty<int>()).Window(3);","handlingStrategy":"validation","validationCode":"if (source == null) throw new InvalidOperationException(\"Cannot window a null source\");\nif (count <= 0) throw new InvalidOperationException(\"Window count must be positive\");\nvar windows = source.Window(count);","typeGuard":"static bool CanWindow<TSource>(IAsyncObservable<TSource>? source, int count)\n    => source is not null && count > 0;","tryCatchPattern":"try { var windows = source.Window(count); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\")\n{\n    // handle missing source (log, substitute empty, or rethrow with context)\n}","preventionTips":["Check receivers before extension-method chains","Enable nullable reference types so null receivers are flagged","Substitute empty observables when a missing source is acceptable","Validate counts and sources together in one guard method"],"tags":["csharp","argument-validation","null-argument","async-rx"],"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"}