{"record":{"id":"9edd27de55dab9f8","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-the-range-of-valid-values-9edd27","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'subscribed')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'subscribed'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs","lineNumber":93,"sourceCode":"        /// <typeparam name=\"T\">The element type of the observable sequence being tested.</typeparam>\n        /// <param name=\"create\">Factory method to create an observable sequence.</param>\n        /// <param name=\"created\">Virtual time at which to invoke the factory to create an observable sequence.</param>\n        /// <param name=\"subscribed\">Virtual time at which to subscribe to the created observable sequence.</param>\n        /// <param name=\"disposed\">Virtual time at which to dispose the subscription.</param>\n        /// <returns>Observer with timestamped recordings of notification messages that were received during the virtual time window when the subscription to the source sequence was active.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"create\"/> is null.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"subscribed\"/> is less than <paramref name=\"created\"/>.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"disposed\"/> is less than <paramref name=\"created\"/> or <paramref name=\"subscribed\"/>.</exception>\n        public ITestableObserver<T> Start<T>(Func<IObservable<T>> create, long created, long subscribed, long disposed)\n        {\n            if (create == null)\n            {\n                throw new ArgumentNullException(nameof(create));\n            }\n\n            if (subscribed < created)\n            {\n                throw new ArgumentOutOfRangeException(nameof(subscribed));\n            }\n            if (disposed < created || disposed < subscribed)\n            {\n                throw new ArgumentOutOfRangeException(nameof(disposed));\n            }\n\n            var source = default(IObservable<T>);\n            var subscription = default(IDisposable);\n            var observer = CreateObserver<T>();\n\n            ScheduleAbsolute(default(object), created, (scheduler, state) => { source = create(); return Disposable.Empty; });\n            ScheduleAbsolute(default(object), subscribed, (scheduler, state) => { subscription = source.Subscribe(observer); return Disposable.Empty; });\n            ScheduleAbsolute(default(object), disposed, (scheduler, state) => { subscription.Dispose(); return Disposable.Empty; });\n\n            Start();\n\n            return observer;\n        }","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs#L75-L111","documentation":"TestScheduler.Start throws ArgumentOutOfRangeException for the 'subscribed' parameter when the virtual time at which the subscription happens is earlier than the virtual time at which the observable is created. The test scheduler enforces monotonic virtual timestamps: created <= subscribed <= disposed. It throws so tests with nonsensical time windows fail fast instead of producing misleading results.","triggerScenarios":"Calling any Start overload (e.g. scheduler.Start(() => xs, created, subscribed, disposed)) with a 'subscribed' value less than the 'created' value, e.g. Start(() => xs, 100, 50, 200) or Start(() => xs, subscribed: 0, ...) after a non-zero created time. Also hit indirectly by the 3-argument Start overload when ReactiveTest.Subscribed (default 200) is less than a custom created value passed in.","commonSituations":"Hand-written marble tests where the author mixes up the ordering of Created (200), Subscribed (300), Disposed (1000) defaults and passes custom values in the wrong order; refactoring tests with custom virtual timestamps; copying a Start call and editing timestamps so subscribed < created.","solutions":["Reorder the timestamps so subscribed >= created (and disposed >= subscribed); typically use ReactiveTest.Created and ReactiveTest.Subscribed defaults","If using Start(create, subscribed, disposed) with custom values, ensure the subscribed value is >= ReactiveTest.Created (200)","Swap arguments if created/subscribed were transposed by mistake"],"exampleFix":"// before\nvar res = scheduler.Start(() => xs, 100, 50, 200);\n// after\nvar res = scheduler.Start(() => xs, 100, 150, 200); // subscribed (150) >= created (100)","handlingStrategy":"validation","validationCode":"// C#\nlong created = ReactiveTest.Created, subscribed = ReactiveTest.Subscribed;\nif (subscribed < created)\n    throw new ArgumentException(\"subscribed must be >= created\");\nvar res = scheduler.Start(() => xs, created, subscribed, ReactiveTest.Disposed);","typeGuard":"static bool IsValidWindow(long created, long subscribed, long disposed) =>\n    created <= subscribed && subscribed <= disposed;","tryCatchPattern":"try { var res = scheduler.Start(() => xs, created, subscribed, disposed); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"subscribed\")\n{\n    // fix timestamps: ensure subscribed >= created\n}","preventionTips":["Default to ReactiveTest.Created/Subscribed/Disposed constants unless you need custom times","Always order custom timestamps: created <= subscribed <= disposed","Write a small helper wrapper around Start that clamps/validates the window"],"tags":["rx","testscheduler","virtual-time","argument-out-of-range"],"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"}