{"record":{"id":"5aa88cc07c889717","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-count-window","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'count')","messagePattern":"Value cannot be null\\. \\(Parameter 'count'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs","lineNumber":126,"sourceCode":"            if (timeSpan < TimeSpan.Zero)\n                throw new ArgumentOutOfRangeException(nameof(timeSpan));\n            if (count <= 0)\n                throw new ArgumentOutOfRangeException(nameof(count));\n\n            return CreateAsyncObservable<IAsyncObservable<TSource>>.From(\n                source,\n                (timeSpan, count),\n                static (source, state, observer) => WindowAsyncCore(source, observer, (o, d) => AsyncObserver.Window(o, d, state.timeSpan, state.count)));\n        }\n\n        public static IAsyncObservable<IAsyncObservable<TSource>> Window<TSource>(this IAsyncObservable<TSource> source, TimeSpan timeSpan, int count, IAsyncScheduler scheduler)\n        {\n            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,","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs#L108-L144","documentation":"The Window(source, timeSpan, count, scheduler) overload throws ArgumentOutOfRangeException when count is less than or equal to zero (runtime message: 'Value cannot be null. (Parameter count)'). Each window must hold at least one element, so non-positive counts are invalid and rejected before the operator is constructed.","triggerScenarios":"Calling source.Window(timeSpan, count, scheduler) with count <= 0, often a batch-size setting of 0 or a computed size from an empty collection.","commonSituations":"Config file with PageSize=0; division-based sizing rounding down to 0; uninitialized int fields; tests parameterizing count as 0 to check edge behavior.","solutions":["Pass a count of at least 1.","Enforce positive batch size when reading configuration (fail fast with a clear config error).","Normalize computed sizes: count = Math.Max(1, computed)."],"exampleFix":"// before\nvar windows = events.Window(TimeSpan.FromSeconds(10), settings.MaxItems, scheduler);\n// after\nif (settings.MaxItems <= 0) throw new InvalidConfigException(\"MaxItems must be positive\");\nvar windows = events.Window(TimeSpan.FromSeconds(10), settings.MaxItems, scheduler);","handlingStrategy":"validation","validationCode":"if (count <= 0) throw new ArgumentException(\"window count must be >= 1\", nameof(count));\ncount = Math.Max(1, count);\nvar windows = source.Window(timeSpan, count, scheduler);","typeGuard":"static bool IsValidWindowSize(int n) => n > 0;","tryCatchPattern":"try { var windows = source.Window(ts, count, sched); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"count\") { /* fix batch size source and retry */ }","preventionTips":["Treat batch/window size config as required-positive at load","Floor computed sizes at 1 with Math.Max","Cover zero/negative size cases in unit tests"],"tags":["argument-out-of-range","window-size","async-rx","window-operator"],"backgroundTag":"value-out-of-range","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"}