{"record":{"id":"fed927e792b9fc2c","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-the-range-of-valid-values-fed927","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'window')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'window'\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs","lineNumber":60,"sourceCode":"\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source, int bufferSize, IAsyncScheduler scheduler)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\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));\n        }\n\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source, TimeSpan window)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (window < TimeSpan.Zero)\n                throw new ArgumentOutOfRangeException(nameof(window));\n\n            return Multicast(source, new SequentialReplayAsyncSubject<TSource>(window));\n        }\n\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source, TimeSpan window, IAsyncScheduler scheduler)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\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));\n        }\n\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source, int bufferSize, TimeSpan window)\n        {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs#L42-L78","documentation":"This ArgumentOutOfRangeException is thrown by the Replay<TSource>(source, TimeSpan window) operator when a negative replay window is passed. System.Reactive.Async requires window >= TimeSpan.Zero because the SequentialReplayAsyncSubject replays only items observed within the trailing window; a negative duration is meaningless. The throw is an eager, fail-fast argument validation performed before any subscription happens.","triggerScenarios":"Calling Observable.Replay(source, TimeSpan.FromSeconds(-1)) or any Replay overload where the window TimeSpan was computed to a negative value (e.g. subtracting timestamps out of order, or a negative config value passed through).","commonSituations":"Reading a replay window from configuration where the value is negative or a negative Duration was computed from misordered timestamps (endTime - startTime with startTime > endTime); unit tests probing invalid inputs.","solutions":["Inspect the TimeSpan value passed as 'window' and ensure it is >= TimeSpan.Zero before calling Replay","Fix the computation producing the window (e.g. clamp with TimeSpan.FromTicks(Math.Max(0, diff.Ticks)))","Validate configuration values for negative durations at startup and fail with a clear message"],"exampleFix":"// before\nvar window = endTime - startTime;\nvar replayed = source.Replay(window);\n// after\nvar window = endTime - startTime;\nif (window < TimeSpan.Zero) window = TimeSpan.Zero;\nvar replayed = source.Replay(window);","handlingStrategy":"validation","validationCode":"if (window < TimeSpan.Zero)\n    throw new ArgumentOutOfRangeException(nameof(window), \"Replay window must be non-negative.\");\nvar replayed = source.Replay(window);","typeGuard":"static bool IsValidReplayWindow(TimeSpan window) => window >= TimeSpan.Zero;","tryCatchPattern":"try\n{\n    var replayed = source.Replay(window);\n}\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"window\")\n{\n    // fall back to zero window or log configuration error\n}","preventionTips":["Clamp computed TimeSpans with Math.Max(0, ticks) before use","Validate duration configuration values at startup","Never subtract timestamps without ordering them first"],"tags":["argument-out-of-range","timespan","reactive","replay"],"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"}