{"record":{"id":"03d19cbfc49d3907","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-the-range-of-valid-values-03d19c","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'time')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'time'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.cs","lineNumber":208,"sourceCode":"        /// Stops the virtual time scheduler.\n        /// </summary>\n        public void Stop()\n        {\n            IsEnabled = false;\n        }\n\n        /// <summary>\n        /// Advances the scheduler's clock to the specified time, running all work till that point.\n        /// </summary>\n        /// <param name=\"time\">Absolute time to advance the scheduler's clock to.</param>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"time\"/> is in the past.</exception>\n        /// <exception cref=\"InvalidOperationException\">The scheduler is already running. VirtualTimeScheduler doesn't support running nested work dispatch loops. To simulate time slippage while running work on the scheduler, use <see cref=\"Sleep\"/>.</exception>\n        public void AdvanceTo(TAbsolute time)\n        {\n            var dueToClock = Comparer.Compare(time, Clock);\n            if (dueToClock < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(time));\n            }\n\n            if (dueToClock == 0)\n            {\n                return;\n            }\n\n            if (!IsEnabled)\n            {\n                IsEnabled = true;\n                do\n                {\n                    var next = GetNext();\n                    if (next != null && Comparer.Compare(next.DueTime, time) <= 0)\n                    {\n                        if (Comparer.Compare(next.DueTime, Clock) > 0)\n                        {\n                            Clock = next.DueTime;","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.cs#L190-L226","documentation":"AdvanceTo moves the virtual clock forward to an absolute time, running all due work. If the requested time compares earlier than the current Clock (Comparer.Compare(time, Clock) < 0), time would run backwards, which virtual time cannot do, so ArgumentOutOfRangeException is thrown.","triggerScenarios":"Calling AdvanceTo(t) where t < scheduler.Clock, e.g. calling AdvanceTo(0) after the clock already advanced, or passing a time captured before earlier AdvanceTo/AdvanceBy calls.","commonSituations":"Test sequences where steps are reordered or times are hardcoded and overlap; reusing a stale timestamp variable across test cases; mixing AdvanceTo with an already-advanced TestScheduler.","solutions":["Pass a time >= scheduler.Clock; clamp with Math.Max(time, scheduler.Clock) if monotonicity is uncertain.","Use GetNow()/scheduler.Clock as the reference instead of a stale stored value.","Reorder test steps so AdvanceTo targets increase monotonically, or use a fresh scheduler instance."],"exampleFix":"// before\nscheduler.AdvanceTo(0); // Clock already at 100\n// after\nscheduler.AdvanceTo(Math.Max(0, scheduler.Clock));","handlingStrategy":"validation","validationCode":"if (scheduler.Comparer.Compare(time, scheduler.Clock) < 0)\n    throw new ArgumentOutOfRangeException(nameof(time), \"time is before the current scheduler clock\");","typeGuard":"bool CanAdvanceTo<TAbsolute>(VirtualTimeSchedulerBase<TAbsolute, TRelative> s, TAbsolute t) where TAbsolute : IComparable<TAbsolute> => s.Comparer.Compare(t, s.Clock) >= 0;","tryCatchPattern":"try { scheduler.AdvanceTo(time); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"time\") { /* clamp or use scheduler.Clock instead */ }","preventionTips":["Track the current clock via scheduler.Clock rather than stored timestamps.","Keep a monotonic list of target times in test scenarios and assert each is >= the last.","Clamp targets with Math.Max relative to the clock when order is uncertain."],"tags":["rx","argument-out-of-range","virtual-time","test-scheduler"],"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"}