{"record":{"id":"4b2f0c847f4bf623","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-subscriptiondelay","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(subscriptionDelay));","messagePattern":"throw new ArgumentNullException\\(nameof\\(subscriptionDelay\\)\\);","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":462,"sourceCode":"        /// Time shifts the observable sequence based on a subscription delay and a delay selector function for each element.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TDelay\">The type of the elements in the delay sequences used to denote the delay duration of each element in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to delay values for.</param>\n        /// <param name=\"subscriptionDelay\">Sequence indicating the delay for the subscription to the source.</param>\n        /// <param name=\"delayDurationSelector\">Selector function to retrieve a sequence indicating the delay for each given element.</param>\n        /// <returns>Time-shifted sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"subscriptionDelay\"/> or <paramref name=\"delayDurationSelector\"/> is null.</exception>\n        public static IObservable<TSource> Delay<TSource, TDelay>(this IObservable<TSource> source, IObservable<TDelay> subscriptionDelay, Func<TSource, IObservable<TDelay>> delayDurationSelector)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (subscriptionDelay == null)\n            {\n                throw new ArgumentNullException(nameof(subscriptionDelay));\n            }\n\n            if (delayDurationSelector == null)\n            {\n                throw new ArgumentNullException(nameof(delayDurationSelector));\n            }\n\n            return s_impl.Delay(source, subscriptionDelay, delayDurationSelector);\n        }\n\n        #endregion\n\n        #endregion\n\n        #region + DelaySubscription +\n\n        /// <summary>\n        /// Time shifts the observable sequence by delaying the subscription with the specified relative time duration.","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L444-L480","documentation":"In Delay<TSource,TDelay>(source, subscriptionDelay, delayDurationSelector), the subscriptionDelay observable (which delays the initial subscription) is mandatory and must be non-null; the library throws ArgumentNullException when it is null.","triggerScenarios":"Calling the 3-argument overload with null as the subscriptionDelay parameter, e.g. forgetting to supply an Observable.Timer for the subscription delay or a nullable field that was never assigned.","commonSituations":"Refactoring from the 2-argument selector overload to the 3-argument overload and not understanding subscriptionDelay is required; passing null to 'skip' the subscription delay; DI-provided observables that resolved to null.","solutions":["Pass a real subscription delay, e.g. Observable.Timer(TimeSpan.FromSeconds(1)); use Observable.Timer(TimeSpan.Zero) or Observable.Return(0L) for no subscription delay.","If no subscription delay is needed, switch to the Delay(source, delayDurationSelector) overload.","Fix the producer of subscriptionDelay so it never returns null.","Guard the parameter before the call and throw a descriptive exception or supply a default."],"exampleFix":"// before\nvar delayed = source.Delay(subscriptionDelay, selector); // subscriptionDelay == null\n// after\nvar delayed = source.Delay(Observable.Timer(TimeSpan.Zero), selector);","handlingStrategy":"validation","validationCode":"if (subscriptionDelay is null) subscriptionDelay = Observable.Timer(TimeSpan.Zero);\nvar delayed = source.Delay(subscriptionDelay, selector);","typeGuard":"static bool IsNonNullObservable<T>(IObservable<T>? o) => o is not null;","tryCatchPattern":"try { var delayed = source.Delay(subscriptionDelay, selector); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"subscriptionDelay\") { /* pass Observable.Timer(TimeSpan.Zero) */ }","preventionTips":["Remember subscriptionDelay is required in this overload — pass Observable.Timer(TimeSpan.Zero) to neutralize it","Use the 2-arg selector overload when no subscription delay is needed","Validate injected observable dependencies","Document overload differences in team coding guidelines"],"tags":["rx","argument-null","linq","dotnet"],"backgroundTag":"null-argument","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"}