{"record":{"id":"64b5f02403e6aac0","repo":"dotnet/reactive","slug":"source-parameter-source","errorCode":null,"errorMessage":"source (Parameter 'source')","messagePattern":"source \\(Parameter 'source'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Foundation/AsyncInfoExtensions.cs","lineNumber":30,"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":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Platforms/WinRT/Foundation/AsyncInfoExtensions.cs#L12-L48","documentation":"The ToObservable(this IAsyncAction source) extension converts a WinRT IAsyncAction into an IObservable<Unit> that completes when the async action completes; it throws ArgumentNullException when 'source' is null. Rx needs the actual WinRT async object to attach its AsyncActionCompletedHandler, so a null source cannot be bridged.","triggerScenarios":"Calling source.ToObservable() where source is a null IAsyncAction reference — e.g. a method returning IAsyncAction returned null, or a WinRT API returned a null result.","commonSituations":"Interoping with WinRT APIs that can return null async operations; calling the extension on the result of a factory that failed silently; storing the async action in a nullable field not yet assigned.","solutions":["Ensure the IAsyncAction is non-null before calling ToObservable; fix the producing method to always return a valid action.","Guard the call: if (source != null) { ... ToObservable() ... } else return Observable.Empty<Unit>();","If the producer may return null by design, wrap it in Observable.Defer and check inside."],"exampleFix":"// before\nIAsyncAction action = GetAction(); // may be null\nvar obs = action.ToObservable();\n// after\nvar obs = GetAction() is IAsyncAction action\n    ? action.ToObservable()\n    : Observable.Empty<Unit>();","handlingStrategy":"validation","validationCode":"// csharp\nif (source == null)\n    return Observable.Empty<Unit>();\nvar obs = source.ToObservable();","typeGuard":"// csharp\nbool IsBridgable(IAsyncAction source) => source is not null;","tryCatchPattern":"// csharp\ntry { obs = source.ToObservable(); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { obs = Observable.Throw<Unit>(new InvalidOperationException(\"Async action was null\")); }","preventionTips":["Never let WinRT interop methods return null IAsyncAction; return Task-based APIs or fail fast","Use Observable.Defer to evaluate the source lazily and check for null at subscription time","Keep nullable annotations on async-operation fields"],"tags":["null-argument","winrt","async","csharp"],"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"}