{"record":{"id":"bea4260bd951ecad","repo":"dotnet/reactive","slug":"argumentnullexception-progressselector","errorCode":null,"errorMessage":"ArgumentNullException: progressSelector","messagePattern":"ArgumentNullException: progressSelector","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive.WindowsRuntime/System.Reactive.Linq/AsyncInfoObservable.cs","lineNumber":88,"sourceCode":"        /// Creates a Windows Runtime asynchronous action that represents the completion of the observable sequence, using a selector function to map the source sequence on a progress reporting sequence.\n        /// Upon cancellation of the asynchronous action, the subscription to the source sequence will be disposed.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TProgress\">The type of the elements in the progress sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to expose as an asynchronous action and to compute a progress sequence that gets reported through the asynchronous action.</param>\n        /// <param name=\"progressSelector\">Selector function to map the source sequence on a progress reporting sequence.</param>\n        /// <returns>Windows Runtime asynchronous action object representing the completion of the result sequence, reporting progress computed through the progress sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"progressSelector\"/> is null.</exception>\n        public static IAsyncActionWithProgress<TProgress> ToAsyncActionWithProgress<TSource, TProgress>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TProgress>> progressSelector)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (progressSelector == null)\n            {\n                throw new ArgumentNullException(nameof(progressSelector));\n            }\n\n            return AsyncInfo.Run<TProgress>((ct, progress) =>\n            {\n                return Observable.Create<TSource?>(observer =>\n                {\n                    var obs = Observer.Synchronize(observer);\n\n                    var data = source.Publish();\n\n                    var progressSubscription = progressSelector(data).Subscribe(progress.Report, obs.OnError);\n                    var dataSubscription = data.DefaultIfEmpty().Subscribe(obs);\n                    var connection = data.Connect();\n\n                    return StableUncheckedCompositeDisposable.CreateTrusted(progressSubscription, dataSubscription, connection);\n                }).ToTask(ct);\n            });\n        }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive.WindowsRuntime/System.Reactive.Linq/AsyncInfoObservable.cs#L70-L106","documentation":"In the same ToAsyncActionWithProgress overload, after source is validated, a null progressSelector (Func<IObservable<TSource>, IObservable<TProgress>>) throws ArgumentNullException('progressSelector'). The selector is required to compute progress notifications from the source sequence.","triggerScenarios":"Calling source.ToAsyncActionWithProgress(null) or passing a selector variable/expression that evaluates to null.","commonSituations":"Optional selector parameters forwarded as-is, conditional selector construction returning null, refactoring that removed the lambda but left the call.","solutions":["Pass a valid Func<IObservable<TSource>, IObservable<TProgress>>.","Null-check or default the selector before calling (e.g. src => Observable.Return(100)).","Fix argument order if null is landing in the selector slot by mistake."],"exampleFix":"// before\nsource.ToAsyncActionWithProgress(progressSelector); // progressSelector == null\n// after\nvar sel = progressSelector ?? (src => Observable.Return(100));\nsource.ToAsyncActionWithProgress(sel);","handlingStrategy":"validation","validationCode":"if (progressSelector is null)\n    progressSelector = src => Observable.Return(100); // or throw with clear message","typeGuard":"bool HasSelector<TSource,TProgress>(Func<IObservable<TSource>, IObservable<TProgress>>? sel) => sel is not null;","tryCatchPattern":"try { var a = source.ToAsyncActionWithProgress(progressSelector); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"progressSelector\") { /* supply selector */ }","preventionTips":["Never pass null selectors; use identity/constant-progress defaults.","Verify argument order in generic overloads (TSource, TProgress).","Document required selectors in wrappers."],"tags":["csharp","winrt","asyncinfo","null-argument","progress"],"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"}