{"record":{"id":"0af9af59957e673f","repo":"dotnet/reactive","slug":"argumentnullexception-source-asyncinfoobservable","errorCode":null,"errorMessage":"ArgumentNullException: source","messagePattern":"ArgumentNullException: source","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive.WindowsRuntime/System.Reactive.Linq/AsyncInfoObservable.cs","lineNumber":39,"sourceCode":"    /// </summary>\n    [CLSCompliant(false)]\n    public static class AsyncInfoObservable\n    {\n        #region IAsyncAction\n\n        /// <summary>\n        /// Creates a Windows Runtime asynchronous action that represents the completion of the observable 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        /// <param name=\"source\">Source sequence to expose as an asynchronous action.</param>\n        /// <returns>Windows Runtime asynchronous action object representing the completion of the observable sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        public static IAsyncAction ToAsyncAction<TSource>(this IObservable<TSource> source)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            return AsyncInfo.Run(ct => (Task)source.DefaultIfEmpty().ToTask(ct));\n        }\n\n        #region Progress\n\n        /// <summary>\n        /// Creates a Windows Runtime asynchronous action that represents the completion of the observable sequence, reporting incremental progress for each element produced by the 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        /// <param name=\"source\">Source sequence to expose as an asynchronous action.</param>\n        /// <returns>Windows Runtime asynchronous action object representing the completion of the observable sequence, reporting incremental progress for each source sequence element.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        public static IAsyncActionWithProgress<int> ToAsyncActionWithProgress<TSource>(this IObservable<TSource> source)\n        {\n            if (source == null)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive.WindowsRuntime/System.Reactive.Linq/AsyncInfoObservable.cs#L21-L57","documentation":"The ToAsyncAction extension converts an IObservable<TSource> into a WinRT IAsyncAction; a null source throws ArgumentNullException('source'). The library checks before wrapping the sequence via AsyncInfo.Run so the failure is immediate rather than when the async action starts.","triggerScenarios":"Calling observable.ToAsyncAction() where observable is null, e.g. a method returning IObservable that returned null or an uninitialized field.","commonSituations":"Factory methods that return null on error instead of Observable.Throw, binding results from DI or configuration that were never populated, null result of a conditional expression.","solutions":["Ensure the observable is non-null before calling ToAsyncAction.","If the source may be absent, use Observable.Empty<TSource>() or Observable.Throw instead of null.","Add a null check or coalesce at the call site."],"exampleFix":"// before\nmyObservable.ToAsyncAction(); // myObservable == null\n// after\nvar src = myObservable ?? Observable.Empty<Unit>();\nsrc.ToAsyncAction();","handlingStrategy":"validation","validationCode":"if (source is null) throw new InvalidOperationException(\"source observable not initialized\");\nvar action = (source ?? Observable.Empty<TSource>()).ToAsyncAction();","typeGuard":"bool IsConvertible<TSource>(IObservable<TSource>? s) => s is not null;","tryCatchPattern":"try { var a = source.ToAsyncAction(); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* obtain a valid observable */ }","preventionTips":["Never return null from methods typed IObservable<T>; use Observable.Empty or Observable.Throw.","Use NRT annotations so null sources are caught at compile time.","Check observable fields are initialized before WinRT conversion."],"tags":["csharp","winrt","asyncinfo","null-argument","rx"],"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"}