{"record":{"id":"7f0439008d527226","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-the-range-of-valid-values-7f0439","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'dueTime')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'dueTime'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":1445,"sourceCode":"        /// Observable.Sample set of operators.\n        /// </para>\n        /// <para>\n        /// Specifying a TimeSpan.Zero value for <paramref name=\"dueTime\"/> is not recommended but supported, causing throttling timers to be scheduled\n        /// that are due immediately. However, this doesn't guarantee all elements will be retained in the result sequence. This is a side-effect of the\n        /// asynchrony introduced by the scheduler, where the action to forward the current element may not execute immediately, despite the TimeSpan.Zero\n        /// due time. In such cases, the next element may arrive before the scheduler gets a chance to run the throttling action.\n        /// </para>\n        /// </remarks>\n        public static IObservable<TSource> Throttle<TSource>(this IObservable<TSource> source, TimeSpan dueTime)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (dueTime < TimeSpan.Zero)\n            {\n                throw new ArgumentOutOfRangeException(nameof(dueTime));\n            }\n\n            return s_impl.Throttle(source, dueTime);\n        }\n\n        /// <summary>\n        /// Ignores elements from an observable sequence which are followed by another element within a specified relative time duration, using the specified scheduler to run throttling timers.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to throttle.</param>\n        /// <param name=\"dueTime\">Throttling duration for each element.</param>\n        /// <param name=\"scheduler\">Scheduler to run the throttle timers on.</param>\n        /// <returns>The throttled sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"dueTime\"/> is less than TimeSpan.Zero.</exception>\n        /// <remarks>\n        /// <para>\n        /// This operator throttles the source sequence by holding on to each element for the duration specified in <paramref name=\"dueTime\"/>. If another","sourceCodeStart":1427,"sourceCodeEnd":1463,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L1427-L1463","documentation":"Throttle(source, dueTime) throws ArgumentOutOfRangeException when dueTime is negative. The throttle window is a duration that must be zero or positive; a negative TimeSpan has no valid meaning for the scheduled delay and the library rejects it at argument validation.","triggerScenarios":"Calling source.Throttle(TimeSpan.FromMilliseconds(-1)) or passing a dueTime computed by subtracting timestamps (e.g. TimeSpan.FromTicks(endTicks - startTicks) where the subtraction went negative) or a misconfigured config value like '-500ms'.","commonSituations":"Durations parsed from user config or CLI flags without sign validation; clock/timezone math producing negative deltas; tests with placeholder negative values.","solutions":["Pass a non-negative TimeSpan, e.g. TimeSpan.FromMilliseconds(500).","Clamp or Math.Abs the computed duration before passing it in.","Validate config-supplied durations (reject negatives) at startup."],"exampleFix":"// before\nvar delta = end - start; // can be negative\nsource.Throttle(delta); // throws if negative\n// after\nvar delta = end - start;\nif (delta < TimeSpan.Zero) delta = TimeSpan.Zero;\nsource.Throttle(delta);","handlingStrategy":"validation","validationCode":"if (dueTime < TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(dueTime), dueTime, \"dueTime must be non-negative\");\n// or clamp: dueTime = dueTime < TimeSpan.Zero ? TimeSpan.Zero : dueTime;","typeGuard":"static bool IsValidDueTime(TimeSpan t) => t >= TimeSpan.Zero;","tryCatchPattern":"try { return source.Throttle(dueTime); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"dueTime\") { return source.Throttle(TimeSpan.Zero); }","preventionTips":["Validate TimeSpan config values (sign, magnitude) at startup","Check operand order when computing durations from timestamps","Use TimeSpan.From* factories instead of raw tick arithmetic where possible"],"tags":["reactive","argument-out-of-range","throttle"],"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"}