{"record":{"id":"aff42aabcb26423d","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-aff42a","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive.WindowsRuntime/AsyncInfoObservableExtensions.cs","lineNumber":35,"sourceCode":"    /// Provides conversions from Windows Runtime asynchronous actions and operations to observable sequences.\n    /// </summary>\n    [CLSCompliant(false)]\n    public static class AsyncInfoObservableExtensions\n    {\n        #region IAsyncAction and IAsyncActionWithProgress\n\n        /// <summary>\n        /// Converts a Windows Runtime asynchronous action to an observable sequence.\n        /// Each observer subscribed to the resulting observable sequence will be notified about the action's successful or exceptional completion.\n        /// </summary>\n        /// <param name=\"source\">Asynchronous action to convert.</param>\n        /// <returns>An observable sequence that produces a unit value when the asynchronous action completes, or propagates the exception produced by the asynchronous action.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        public static IObservable<Unit> ToObservable(this IAsyncAction source)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            return new AsyncInfoToObservableBridge<Unit, Unit>(\n                source,\n                static (iai, a) => ((IAsyncAction)iai).Completed += new AsyncActionCompletedHandler((iaa, status) => a(iaa, status)),\n                iai => Unit.Default,\n                onProgress: null,\n                progress: null,\n                multiValue: false\n            );\n        }\n\n        /// <summary>\n        /// Converts a Windows Runtime asynchronous action to an observable sequence, ignoring its progress notifications.\n        /// Each observer subscribed to the resulting observable sequence will be notified about the action's successful or exceptional completion.\n        /// </summary>\n        /// <typeparam name=\"TProgress\">The type of the reported progress objects, which get ignored by this conversion.</typeparam>\n        /// <param name=\"source\">Asynchronous action to convert.</param>","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive.WindowsRuntime/AsyncInfoObservableExtensions.cs#L17-L53","documentation":"The parameterless ToObservable extension for IAsyncAction (WindowsRuntime) throws ArgumentNullException when the WinRT IAsyncAction source is null. The bridge object it constructs hooks the action's Completed event, which requires a live async action instance.","triggerScenarios":"Calling ((IAsyncAction)null).ToObservable(), typically when an async WinRT API returned null instead of an action (some APIs return null on fast-fail or when unsupported).","commonSituations":"UWP/WinRT interop where a projected async operation came back null from a platform call or a mock; calling on platforms where the WinRT type projection is unavailable.","solutions":["Check the IAsyncAction for null before calling ToObservable and handle the null case explicitly.","Fix or guard the WinRT API call so it returns a valid action.","Wrap the conversion so a null source yields an error observable instead of throwing at setup."],"exampleFix":"// before\noperation.ToObservable().Subscribe(...); // operation is null\n// after\nif (operation != null) { operation.ToObservable().Subscribe(...); }\nelse { HandleMissingOperation(); }","handlingStrategy":"validation","validationCode":"if (source is null) { HandleMissingOperation(); return; }\nsource.ToObservable();","typeGuard":"bool HasAction(Windows.Foundation.IAsyncAction a) => a is not null;","tryCatchPattern":"try { source.ToObservable().Subscribe(obs); } catch (ArgumentNullException ex) when (ex.ParamName == \"source\") { Log(\"IAsyncAction was null\"); }","preventionTips":["Check WinRT async return values for null before converting","Treat null async operations from platform APIs as API failures and log them","Wrap conversions in a helper that normalizes null to an error observable"],"tags":["csharp","rx","uwp","winrt","argumentnull"],"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"}