{"record":{"id":"e7400e282e48ca5d","repo":"dotnet/reactive","slug":"count-observable-time","errorCode":null,"errorMessage":"count","messagePattern":"count","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":2426,"sourceCode":"        /// Specifying a TimeSpan.Zero value for <paramref name=\"timeSpan\"/> is not recommended but supported, causing the scheduler to create windows as fast as it can.\n        /// Because all source sequence elements end up in one of the windows, some windows won't have a zero time span. This is a side-effect of the asynchrony introduced\n        /// by the scheduler, where the action to close the current window and to create a new window may not execute immediately, despite the TimeSpan.Zero due time.\n        /// </remarks>\n        public static IObservable<IObservable<TSource>> Window<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, int count, IScheduler scheduler)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (timeSpan < TimeSpan.Zero)\n            {\n                throw new ArgumentOutOfRangeException(nameof(timeSpan));\n            }\n\n            if (count <= 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(count));\n            }\n\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return s_impl.Window(source, timeSpan, count, scheduler);\n        }\n\n        #endregion\n\n        #endregion\n    }\n}\n","sourceCodeStart":2408,"sourceCodeEnd":2442,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L2408-L2442","documentation":"Window(source, timeSpan, count, scheduler) uses count as the maximum number of elements per window and requires it to be strictly positive. When count is zero or negative it throws ArgumentOutOfRangeException immediately. A window must be able to contain at least one element for the operator to be meaningful.","triggerScenarios":"Calling Window with count = 0, a negative count, or a count computed from an empty/uninitialized configuration value (e.g. int parsed from empty string defaulting to 0).","commonSituations":"Batch-size settings read from config defaulting to 0, off-by-one arithmetic producing 0, division-based sizing (totalItems / groups) that rounds to 0 for small totals.","solutions":["Pass a count >= 1; validate before calling Window","Fix the config or computation that yielded 0/negative (e.g. Math.Max(1, computedCount))","If you intended a time-only window, use the Window(source, timeSpan, scheduler) overload that has no count"],"exampleFix":"// before\nvar windows = source.Window(TimeSpan.FromSeconds(1), batchSize, Scheduler.Default); // batchSize == 0\n// after\nvar windows = source.Window(TimeSpan.FromSeconds(1), Math.Max(1, batchSize), Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count), \"Window count must be at least 1.\");","typeGuard":null,"tryCatchPattern":"try { var windows = source.Window(ts, count, scheduler); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"count\") { log.Error(\"Invalid window count\", ex); }","preventionTips":["Clamp computed batch sizes with Math.Max(1, n)","Validate batch/window size settings loaded from config at startup","Use the time-only Window overload when a count is not intended"],"tags":["csharp","argument-out-of-range","windowing","reactive-extensions"],"backgroundTag":"argument-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"}