{"record":{"id":"b19d33e1ff0217bf","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(timeoutDurationSelector));","messagePattern":"throw new ArgumentNullException\\(nameof\\(timeoutDurationSelector\\)\\);","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":1904,"sourceCode":"        /// Applies a timeout policy to the observable sequence based on a timeout duration computed for each element.\n        /// If the next element isn't received within the computed duration starting from its predecessor, a TimeoutException is propagated to the observer.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TTimeout\">The type of the elements in the timeout sequences used to indicate the timeout duration for each element in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to perform a timeout for.</param>\n        /// <param name=\"timeoutDurationSelector\">Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.</param>\n        /// <returns>The source sequence with a TimeoutException in case of a timeout.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"timeoutDurationSelector\"/> is null.</exception>\n        public static IObservable<TSource> Timeout<TSource, TTimeout>(this IObservable<TSource> source, Func<TSource, IObservable<TTimeout>> timeoutDurationSelector)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (timeoutDurationSelector == null)\n            {\n                throw new ArgumentNullException(nameof(timeoutDurationSelector));\n            }\n\n            return s_impl.Timeout(source, timeoutDurationSelector);\n        }\n\n        /// <summary>\n        /// Applies a timeout policy to the observable sequence based on a timeout duration computed for each element.\n        /// If the next element isn't received within the computed duration starting from its predecessor, the other observable sequence is used to produce future messages from that point on.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence and the other sequence used upon a timeout.</typeparam>\n        /// <typeparam name=\"TTimeout\">The type of the elements in the timeout sequences used to indicate the timeout duration for each element in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to perform a timeout for.</param>\n        /// <param name=\"timeoutDurationSelector\">Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.</param>\n        /// <param name=\"other\">Sequence to return in case of a timeout.</param>\n        /// <returns>The source sequence switching to the other sequence in case of a timeout.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"timeoutDurationSelector\"/> or <paramref name=\"other\"/> is null.</exception>\n        public static IObservable<TSource> Timeout<TSource, TTimeout>(this IObservable<TSource> source, Func<TSource, IObservable<TTimeout>> timeoutDurationSelector, IObservable<TSource> other)\n        {","sourceCodeStart":1886,"sourceCodeEnd":1922,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L1886-L1922","documentation":"The Timeout(source, timeoutDurationSelector) overload throws ArgumentNullException because the timeoutDurationSelector delegate is null. This selector computes a per-item timeout stream, so it is mandatory for the operator. The check runs eagerly when the query is composed.","triggerScenarios":"Calling source.Timeout(selector) with a null Func<TSource, IObservable<TTimeout>, e.g. an optional selector parameter left at its default of null.","commonSituations":"Optional method parameters of type Func<T,...> defaulting to null and passed straight through; a strategy object whose selector delegate was never assigned; reflection-based invocation with missing configuration.","solutions":["Pass a real selector, e.g. item => Observable.Timer(TimeSpan.FromSeconds(1))","If the selector is optional, provide a default like _ => Observable.Never<TTimeout>()","Guard the delegate for null before composing the query"],"exampleFix":"// before\nsource.Timeout(_timeoutSelector)\n// after\nvar selector = _timeoutSelector ?? (_ => Observable.Timer(TimeSpan.FromSeconds(10)));\nsource.Timeout(selector)","handlingStrategy":"validation","validationCode":"if (timeoutDurationSelector is null)\n    throw new InvalidOperationException(\"timeoutDurationSelector must be provided.\");\n// or default it:\nvar selector = timeoutDurationSelector ?? (_ => Observable.Never<TTimeout>());","typeGuard":"static bool IsValidSelector<TSource, TTimeout>(Func<TSource, IObservable<TTimeout>> f) => f is not null;","tryCatchPattern":"try\n{\n    result = source.Timeout(selector);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"timeoutDurationSelector\")\n{\n    result = source.Timeout(_ => Observable.Never<TTimeout>());\n}","preventionTips":["Do not give optional Func parameters a default of null; require them or default to Observable.Never<T>()","Wire strategy/policy delegates in the constructor so they cannot be unset","Validate delegates at the boundary where configuration is loaded"],"tags":["argumentnull","reactive-extensions","delegate","argument-validation"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}