{"record":{"id":"5b18c42781813880","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-range-of-valid-values-5b18c4","errorCode":null,"errorMessage":"Specified argument was out of range of valid values. (Parameter 'window')","messagePattern":"Specified argument was out of range of valid values\\. \\(Parameter 'window'\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs","lineNumber":881,"sourceCode":"        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"bufferSize\"/> is less than zero.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"window\"/> is less than TimeSpan.Zero.</exception>\n        /// <remarks>Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy.</remarks>\n        /// <seealso cref=\"ReplaySubject{T}\"/>\n        public static IConnectableObservable<TSource> Replay<TSource>(this IObservable<TSource> source, int bufferSize, TimeSpan window, IScheduler scheduler)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (bufferSize < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(bufferSize));\n            }\n\n            if (window < TimeSpan.Zero)\n            {\n                throw new ArgumentOutOfRangeException(nameof(window));\n            }\n\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return s_impl.Replay(source, bufferSize, window, scheduler);\n        }\n\n        /// <summary>\n        /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length and element count for the replay buffer.\n        /// This operator is a specialization of Multicast using a <see cref=\"ReplaySubject{T}\"/>.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence.</typeparam>\n        /// <param name=\"source\">Source sequence whose elements will be multicasted through a single shared subscription.</param>\n        /// <param name=\"selector\">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.</param>","sourceCodeStart":863,"sourceCodeEnd":899,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs#L863-L899","documentation":"The window parameter of Replay(source, bufferSize, window, scheduler) defines the time span for which notifications are replayed and must not be negative. A negative TimeSpan is rejected eagerly with ArgumentOutOfRangeException (message parameter 'window').","triggerScenarios":"Calling source.Replay(bufferSize, negativeTimeSpan, scheduler), e.g. TimeSpan.FromSeconds(-5) or a TimeSpan computed by subtraction (later - earlier) that came out negative.","commonSituations":"Duration loaded from config where units were misread (milliseconds vs seconds) yielding a negative value; clock/timestamp subtraction without Math.Abs; refactored constant with a stray minus sign.","solutions":["Pass a non-negative TimeSpan (use TimeSpan.Zero for no window trimming)","Apply TimeSpan.FromTicks(Math.Abs(ts.Ticks)) if the value is derived from a difference","Validate the configured duration at startup"],"exampleFix":"// before\nvar conn = source.Replay(10, TimeSpan.FromSeconds(-5), scheduler);\n// after\nvar conn = source.Replay(10, TimeSpan.FromSeconds(5), scheduler);","handlingStrategy":"validation","validationCode":"if (window < TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(window));","typeGuard":"static bool IsValidWindow(TimeSpan window) => window >= TimeSpan.Zero;","tryCatchPattern":"try { var conn = src.Replay(size, window, scheduler); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"window\") { window = TimeSpan.Zero; /* retry */ }","preventionTips":["Use Math.Abs when windows derive from timestamp differences","Parse duration config with sign checks","Define non-negative TimeSpan constants for defaults"],"tags":["csharp","rx","timespan"],"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-23T08:17:48.524Z"}