{"record":{"id":"e300ef45bb0aa3b4","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-the-range-of-valid-values-e300ef","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'period')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'period'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Concurrency/DefaultScheduler.cs","lineNumber":97,"sourceCode":"\n            return workItem;\n        }\n\n        /// <summary>\n        /// Schedules a periodic piece of work, using a System.Threading.Timer object.\n        /// </summary>\n        /// <typeparam name=\"TState\">The type of the state passed to the scheduled action.</typeparam>\n        /// <param name=\"state\">Initial state passed to the action upon the first iteration.</param>\n        /// <param name=\"period\">Period for running the work periodically.</param>\n        /// <param name=\"action\">Action to be executed, potentially updating the state.</param>\n        /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"period\"/> is less than <see cref=\"TimeSpan.Zero\"/>.</exception>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"action\"/> is <c>null</c>.</exception>\n        public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)\n        {\n            if (period < TimeSpan.Zero)\n            {\n                throw new ArgumentOutOfRangeException(nameof(period));\n            }\n\n            if (action == null)\n            {\n                throw new ArgumentNullException(nameof(action));\n            }\n\n            return new PeriodicallyScheduledWorkItem<TState>(state, period, action);\n        }\n\n        private sealed class PeriodicallyScheduledWorkItem<TState> : IDisposable\n        {\n            private TState _state;\n            private Func<TState, TState> _action;\n            private readonly IDisposable _cancel;\n            private readonly AsyncLock _gate = new();\n\n            public PeriodicallyScheduledWorkItem(TState state, TimeSpan period, Func<TState, TState> action)","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Concurrency/DefaultScheduler.cs#L79-L115","documentation":"DefaultScheduler.SchedulePeriodic<TState> schedules a recurring state-transforming action; the period is checked first and must be greater than or equal to TimeSpan.Zero. Negative periods are rejected with ArgumentOutOfRangeException before the action null-check and work-item creation.","triggerScenarios":"Calling scheduler.SchedulePeriodic(state, TimeSpan.FromSeconds(-1), next) or any negative TimeSpan period, often from a computed or configured interval.","commonSituations":"Polling intervals read from config where a negative value slipped in, subtracting DateTimes to get the interval, or unit tests probing boundary behavior of periodic scheduling.","solutions":["Validate the period before scheduling: if (period < TimeSpan.Zero) throw new ArgumentException(...).","Clamp to TimeSpan.Zero or a sensible minimum instead of passing the raw value.","Fix the interval computation/source so it can no longer produce negative TimeSpans."],"exampleFix":"// before\nvar period = end - start; // negative when start > end\nscheduler.SchedulePeriodic(0L, period, n => n + 1);\n\n// after\nvar period = end - start;\nif (period < TimeSpan.Zero) period = TimeSpan.FromMinutes(1);\nscheduler.SchedulePeriodic(0L, period, n => n + 1);","handlingStrategy":"validation","validationCode":"if (period < TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(period));\nif (period == TimeSpan.Zero) period = TimeSpan.FromMilliseconds(1); // or keep Zero intentionally\nscheduler.SchedulePeriodic(state, period, next);","typeGuard":null,"tryCatchPattern":"try { scheduler.SchedulePeriodic(state, period, next); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"period\") { /* clamp period and retry */ }","preventionTips":["Validate all configured intervals are >= TimeSpan.Zero","Guard DateTime/TimeSpan subtraction results","Document Zero-period semantics for callers"],"tags":["argument-out-of-range","periodic-timer","scheduling"],"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"}