{"record":{"id":"b46c7c16952cc912","repo":"dotnet/reactive","slug":"throw-new-argumentoutofrangeexception-nameof-duetime","errorCode":null,"errorMessage":"throw new ArgumentOutOfRangeException(nameof(dueTime));","messagePattern":"throw new ArgumentOutOfRangeException\\(nameof\\(dueTime\\)\\);","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Throttle.cs","lineNumber":18,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Reactive.Concurrency;\nusing System.Reactive.Disposables;\nusing System.Threading;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TSource> Throttle<TSource>(this IAsyncObservable<TSource> source, TimeSpan dueTime)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (dueTime < TimeSpan.Zero)\n                throw new ArgumentOutOfRangeException(nameof(dueTime));\n\n            return CreateAsyncObservable<TSource>.From(\n                source,\n                dueTime,\n                static async (source, dueTime, observer) =>\n                {\n                    var d = new CompositeAsyncDisposable();\n\n                    var (sink, throttler) = AsyncObserver.Throttle(observer, dueTime);\n\n                    await d.AddAsync(throttler).ConfigureAwait(false);\n\n                    var sourceSubscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    await d.AddAsync(sourceSubscription).ConfigureAwait(false);\n\n                    return d;\n                });","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Throttle.cs#L1-L36","documentation":"Throttle throws ArgumentOutOfRangeException when dueTime is negative (less than TimeSpan.Zero). A negative quiet period has no meaning for the underlying scheduler delay, so the library rejects it at call time.","triggerScenarios":"Calling AsyncObservable.Throttle(source, TimeSpan.FromSeconds(-1)) or computing a delay from data that can go negative (e.g. subtraction of timestamps, user-provided negative input).","commonSituations":"Parsing a debounce interval from config/user input without validating sign; computing dueTime as targetTime - now after the target already passed; unit tests with sentinel negative values.","solutions":["Clamp or validate the delay before calling: if (ts < TimeSpan.Zero) ts = TimeSpan.Zero","Fix the calculation producing the negative TimeSpan","Validate user/config-provided debounce values at load time"],"exampleFix":"// before\nvar due = end - start; // can be negative\nvar throttled = AsyncObservable.Throttle(source, due);\n// after\nvar due = end - start;\nif (due < TimeSpan.Zero) due = TimeSpan.Zero;\nvar throttled = AsyncObservable.Throttle(source, due);","handlingStrategy":"validation","validationCode":"if (dueTime < TimeSpan.Zero)\n    throw new ArgumentOutOfRangeException(nameof(dueTime));\nvar throttled = AsyncObservable.Throttle(source, dueTime);","typeGuard":"static bool IsValidDueTime(TimeSpan t) => t >= TimeSpan.Zero;","tryCatchPattern":"try { var throttled = AsyncObservable.Throttle(source, due); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"dueTime\") { due = TimeSpan.Zero; }","preventionTips":["Clamp computed delays with Math.Max(TimeSpan.Zero, ts)","Validate user/config-supplied debounce intervals for sign at load time","Be careful subtracting timestamps — elapsed-time computations can go negative"],"tags":["csharp","async-rx","argument-out-of-range","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-15T23:17:13.987Z"}