{"record":{"id":"eca37d9370470f9e","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-throttleselector","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(throttleSelector));","messagePattern":"throw new ArgumentNullException\\(nameof\\(throttleSelector\\)\\);","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Throttle.cs","lineNumber":72,"sourceCode":"\n                    var (sink, throttler) = AsyncObserver.Throttle(observer, state.dueTime, state.scheduler);\n\n                    await d.AddAsync(throttler).ConfigureAwait(false);\n\n                    var sourceSubscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    await d.AddAsync(sourceSubscription).ConfigureAwait(false);\n\n                    return d;\n                });\n        }\n\n        public static IAsyncObservable<TSource> Throttle<TSource, TThrottle>(this IAsyncObservable<TSource> source, Func<TSource, IAsyncObservable<TThrottle>> throttleSelector)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (throttleSelector == null)\n                throw new ArgumentNullException(nameof(throttleSelector));\n\n            return CreateAsyncObservable<TSource>.From(\n                source,\n                throttleSelector,\n                static async (source, throttleSelector, observer) =>\n                {\n                    var d = new CompositeAsyncDisposable();\n\n                    var (sink, throttler) = AsyncObserver.Throttle(observer, throttleSelector);\n\n                    await d.AddAsync(throttler).ConfigureAwait(false);\n\n                    var sourceSubscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    await d.AddAsync(sourceSubscription).ConfigureAwait(false);\n\n                    return d;\n                });","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Throttle.cs#L54-L90","documentation":"In the selector-based Throttle overload, the throttleSelector function produces the per-item throttle duration sequence. It is essential to the operator's behavior, so a null selector is rejected up front with ArgumentNullException.","triggerScenarios":"Calling source.Throttle((Func<TSource, IAsyncObservable<TThrottle>>)null), e.g. passing a selector variable that was never assigned or a conditional expression that evaluated to null.","commonSituations":"Building the selector dynamically (reflection, dictionary of delegates) and the lookup missed; a class member Func field is null until initialized; method-group binding failed and returned null via reflection.","solutions":["Pass a non-null lambda, e.g. source.Throttle(x => AsyncObservable.Timer(dueTimeFor(x)))","Initialize or register the delegate before use","Guard the call site: if (selector != null) ... else use the TimeSpan overload"],"exampleFix":"// before\nFunc<int, IAsyncObservable<long>> sel = lookup[\"throttle\"] as Func<int, IAsyncObservable<long>>; // null if missing\nvar throttled = source.Throttle(sel);\n// after\nvar throttled = source.Throttle(x => AsyncObservable.Timer(TimeSpan.FromMilliseconds(x)));","handlingStrategy":"validation","validationCode":"if (selector is null) throw new ArgumentNullException(nameof(selector));","typeGuard":"static bool IsValidSelector<TSource,TThrottle>(Func<TSource, IAsyncObservable<TThrottle>> f) => f is not null;","tryCatchPattern":"try { var t = source.Throttle(selector); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"throttleSelector\") { /* substitute default selector */ }","preventionTips":["Initialize Func fields before pipeline composition","Check reflection/delegate lookups for null before invoking the operator","Prefer passing lambdas inline over storing them in nullable members"],"tags":["argument-null","reactive-operators","delegate"],"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"}