{"record":{"id":"2a96c68068130e69","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-the-range-of-valid-values-2a96c6","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'disposed')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'disposed'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs","lineNumber":97,"sourceCode":"        /// <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        }\n\n        /// <summary>\n        /// Starts the test scheduler and uses the specified virtual time to dispose the subscription to the sequence obtained through the factory function.\n        /// Default virtual times are used for <see cref=\"ReactiveTest.Created\">factory invocation</see> and <see cref=\"ReactiveTest.Subscribed\">sequence subscription</see>.","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs#L79-L115","documentation":"TestScheduler.Start throws ArgumentOutOfRangeException for the 'disposed' parameter when the virtual disposal time is earlier than the creation time or earlier than the subscription time. The library requires created <= subscribed <= disposed so the test's virtual-time window is coherent; it fails fast to prevent tests that dispose an observable before it was subscribed.","triggerScenarios":"Calling Start(create, created, subscribed, disposed) with disposed < created or disposed < subscribed, e.g. scheduler.Start(() => xs, 100, 200, 150). Also occurs with the Start(create, disposed) overload when a disposed value less than ReactiveTest.Subscribed (300) is passed, e.g. Start(() => xs, 100).","commonSituations":"Authoring marble tests with custom time windows where the disposal tick is set below the subscription tick; using Start(create, disposed) and forgetting the default disposed value must be >= 300 (ReactiveTest.Subscribed); test refactors that shrink the time window.","solutions":["Set disposed to a value >= subscribed (and >= created), e.g. ReactiveTest.Disposed (1000) or larger","If using Start(create, disposed), pass disposed >= ReactiveTest.Subscribed (300)","Extend the virtual time window if subscriptions legitimately need to run longer"],"exampleFix":"// before\nvar res = scheduler.Start(() => xs, 100, 200, 150);\n// after\nvar res = scheduler.Start(() => xs, 100, 200, 1000); // disposed >= subscribed","handlingStrategy":"validation","validationCode":"// C#\nlong disposed = ReactiveTest.Disposed; // 1000\nif (disposed < ReactiveTest.Subscribed)\n    throw new ArgumentException(\"disposed must be >= ReactiveTest.Subscribed (300)\");\nvar res = scheduler.Start(() => xs, ReactiveTest.Created, ReactiveTest.Subscribed, disposed);","typeGuard":"static bool IsValidWindow(long created, long subscribed, long disposed) =>\n    created <= subscribed && subscribed <= disposed;","tryCatchPattern":"try { var res = scheduler.Start(() => xs, disposed: myDisposed); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"disposed\")\n{\n    // use ReactiveTest.Disposed or a larger tick\n}","preventionTips":["Never pass a disposed value below 300 when using the two-argument Start overload","Use ReactiveTest.Disposed as the default disposal tick","Keep custom windows monotonic: created <= subscribed <= disposed"],"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"}