{"record":{"id":"9c5f0e8729e10b70","repo":"dotnet/reactive","slug":"throw-new-argumentoutofrangeexception-nameof-duetime-9c5f0e","errorCode":null,"errorMessage":"throw new ArgumentOutOfRangeException(nameof(dueTime));","messagePattern":"throw new ArgumentOutOfRangeException\\(nameof\\(dueTime\\)\\);","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":291,"sourceCode":"        /// </para>\n        /// <para>\n        /// Observer callbacks for the resulting sequence will be run on the default scheduler. This effect is similar to using ObserveOn.\n        /// </para>\n        /// <para>\n        /// Exceptions signaled by the source sequence through an OnError callback are forwarded immediately to the result sequence. Any OnNext notifications that were in the queue at the point of the OnError callback will be dropped.\n        /// In order to delay error propagation, consider using the <see cref=\"Materialize\">Observable.Materialize</see> and <see cref=\"Dematerialize\">Observable.Dematerialize</see> operators, or use <see cref=\"Observable.DelaySubscription{T}(IObservable{T}, TimeSpan)\">DelaySubscription</see>.\n        /// </para>\n        /// </remarks>\n        public static IObservable<TSource> Delay<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.Delay(source, dueTime);\n        }\n\n        /// <summary>\n        /// Time shifts the observable sequence by the specified relative time duration, using the specified scheduler to run timers.\n        /// The relative time intervals between the values are preserved.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to delay values for.</param>\n        /// <param name=\"dueTime\">Relative time by which to shift the observable sequence. If this value is equal to TimeSpan.Zero, the scheduler will dispatch observer callbacks as soon as possible.</param>\n        /// <param name=\"scheduler\">Scheduler to run the delay timers on.</param>\n        /// <returns>Time-shifted 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>","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L273-L309","documentation":"Observable.Delay throws ArgumentOutOfRangeException when dueTime is negative. dueTime is a scheduler due time used to shift emissions into the future; negative durations are meaningless for Delay (unlike Buffer, Delay here rejects only negative values). The check is performed eagerly at the call site.","triggerScenarios":"Calling Observable.Delay(source, dueTime) with dueTime < TimeSpan.Zero, e.g. TimeSpan.FromSeconds(-1), a negative configured delay, or a duration computed from clock values in the wrong order.","commonSituations":"Delay/timeout settings read from config as negative values; subtracting timestamps with the operands swapped; sign mistakes in dynamic delay computations (e.g. remaining time after a deadline passed).","solutions":["Pass a non-negative TimeSpan, e.g. TimeSpan.FromSeconds(5)","Clamp computed delays: if (delay < TimeSpan.Zero) delay = TimeSpan.Zero;","Validate delay configuration at startup before it reaches the Rx pipeline"],"exampleFix":"// before\nvar delay = deadline - DateTime.Now; // may be negative\nvar delayed = source.Delay(delay);\n// after\nvar delay = deadline - DateTime.Now;\nif (delay < TimeSpan.Zero) delay = TimeSpan.Zero;\nvar delayed = source.Delay(delay);","handlingStrategy":"validation","validationCode":"if (dueTime < TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(dueTime));\n// or clamp: dueTime = dueTime < TimeSpan.Zero ? TimeSpan.Zero : dueTime;","typeGuard":null,"tryCatchPattern":"try { var d = source.Delay(dueTime); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"dueTime\") { dueTime = TimeSpan.Zero; /* retry */ }","preventionTips":["Clamp remaining-time calculations so they never go negative","Validate delay settings at configuration load time","Double-check operand order in duration arithmetic"],"tags":["rx","argument-validation","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"}