{"record":{"id":"7d2d406e7e8062a7","repo":"dotnet/reactive","slug":"window","errorCode":null,"errorMessage":"window","messagePattern":"window","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs","lineNumber":158,"sourceCode":"                throw new ArgumentNullException(nameof(source));\n            if (selector == null)\n                throw new ArgumentNullException(nameof(selector));\n            if (bufferSize < 0)\n                throw new ArgumentOutOfRangeException(nameof(bufferSize));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Multicast(source, () => new SequentialReplayAsyncSubject<TSource>(bufferSize, scheduler), selector);\n        }\n\n        public static IAsyncObservable<TResult> Replay<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, IAsyncObservable<TResult>> selector, TimeSpan window)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (selector == null)\n                throw new ArgumentNullException(nameof(selector));\n            if (window < TimeSpan.Zero)\n                throw new ArgumentOutOfRangeException(nameof(window));\n\n            return Multicast(source, () => new SequentialReplayAsyncSubject<TSource>(window), selector);\n        }\n\n        public static IAsyncObservable<TResult> Replay<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, IAsyncObservable<TResult>> selector, TimeSpan window, IAsyncScheduler scheduler)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (selector == null)\n                throw new ArgumentNullException(nameof(selector));\n            if (window < TimeSpan.Zero)\n                throw new ArgumentOutOfRangeException(nameof(window));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Multicast(source, () => new SequentialReplayAsyncSubject<TSource>(window, scheduler), selector);\n        }\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs#L140-L176","documentation":"The Replay(source, selector, window) overload throws ArgumentOutOfRangeException because the window TimeSpan was negative. The window defines how long past elements stay replayable in the SequentialReplayAsyncSubject, so only TimeSpan.Zero or positive durations are valid. The library rejects negatives eagerly at the call site.","triggerScenarios":"Calling source.Replay(selector, TimeSpan.FromSeconds(-5)) or passing a TimeSpan computed from a subtraction/deserialized config value that ended up negative.","commonSituations":"Window read from configuration with an invalid unit conversion (ms vs s producing negative values); TimeSpan arithmetic that underflows (later - earlier with reversed operands); user-supplied duration not validated upstream.","solutions":["Pass a non-negative TimeSpan (TimeSpan.Zero is allowed).","Clamp before calling: window < TimeSpan.Zero ? TimeSpan.Zero : window.","Fix the computation or configuration source that produced the negative duration."],"exampleFix":"// before\nvar replayed = source.Replay(selector, expiry - now); // can be negative\n// after\nvar window = expiry > now ? expiry - now : TimeSpan.Zero;\nvar replayed = source.Replay(selector, window);","handlingStrategy":"validation","validationCode":"if (window < TimeSpan.Zero) throw new InvalidOperationException(\"window must be >= TimeSpan.Zero\");\n// safe to call source.Replay(selector, window);","typeGuard":"bool IsValidWindow(TimeSpan t) => t >= TimeSpan.Zero;","tryCatchPattern":"try { var r = source.Replay(selector, window); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"window\") { /* clamp to TimeSpan.Zero and retry */ }","preventionTips":["Clamp durations: window < TimeSpan.Zero ? TimeSpan.Zero : window.","Check sign when subtracting DateTimes to compute a window.","Validate user/config-supplied durations at load time."],"tags":["argument-out-of-range","timespan","window"],"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"}