{"record":{"id":"e2d9d21bfabb67b1","repo":"dotnet/reactive","slug":"argumentnullexception","errorCode":null,"errorMessage":"ArgumentNullException","messagePattern":"ArgumentNullException","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/AsyncObservable.cs","lineNumber":21,"sourceCode":"// See the LICENSE file in the project root for more information. \n\nusing System.Reactive.Disposables;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public static partial class AsyncObservable\n    {\n        internal static class CreateAsyncObservable<TResult>\n        {\n            private sealed class AsyncObservableImpl<TSource> : AsyncObservableBase<TResult>\n            {\n                private readonly IAsyncObservable<TSource> _source;\n                private readonly Func<IAsyncObservable<TSource>, IAsyncObserver<TResult>, ValueTask<IAsyncDisposable>> _subscribeAsync;\n\n                public AsyncObservableImpl(IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, IAsyncObserver<TResult>, ValueTask<IAsyncDisposable>> subscribeAsync)\n                {\n                    _source = source ?? throw new ArgumentNullException(nameof(source));\n                    _subscribeAsync = subscribeAsync ?? throw new ArgumentNullException(nameof(subscribeAsync));\n                }\n\n                protected override ValueTask<IAsyncDisposable> SubscribeAsyncCore(IAsyncObserver<TResult> observer)\n                {\n                    if (observer == null)\n                        throw new ArgumentNullException(nameof(observer));\n\n                    return _subscribeAsync(_source, observer);\n                }\n            }\n\n            private sealed class AsyncObservableImpl<TSource, TState> : AsyncObservableBase<TResult>\n            {\n                private readonly TState _state;\n                private readonly IAsyncObservable<TSource> _source;\n                private readonly Func<IAsyncObservable<TSource>, TState, IAsyncObserver<TResult>, ValueTask<IAsyncDisposable>> _subscribeAsync;\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/AsyncObservable.cs#L3-L39","documentation":"AsyncObservableImpl's constructor validates its source observable and throws ArgumentNullException when source is null. Every IAsyncObservable operator implementation must be rooted in a non-null source; a null source would make SubscribeAsyncCore impossible to dispatch. The guard is fail-fast at construction time.","triggerScenarios":"Calling the internal AsyncObservableImpl<TSource, TResult>(null, subscribeAsync) constructor — typically reached via Create/From-style APIs when the upstream observable passed to them is null.","commonSituations":"Chaining operators on an observable variable that was never assigned (e.g. a conditional factory returned null); passing a method result as source without a null check; deserialized or resolved sources that came back null.","solutions":["Ensure the source IAsyncObservable is non-null before passing it (e.g. source ?? AsyncObservable.Empty<T>())","Check why the upstream factory/resolution returned null and fix the root cause","Add an explicit null check with a clear message at the point where source is produced"],"exampleFix":"// before\nvar result = AsyncObservable.Select(GetSource(), x => x * 2); // GetSource() returned null\n// after\nvar src = GetSource() ?? AsyncObservable.Empty<int>();\nvar result = AsyncObservable.Select(src, x => x * 2);","handlingStrategy":"validation","validationCode":"if (source == null) throw new InvalidOperationException(\"source observable must be provided\");","typeGuard":"static bool HasSource<T>(IAsyncObservable<T> src) => src is not null;","tryCatchPattern":"try { var obs = AsyncObservable.Create(source, subscribe); } catch (ArgumentNullException ex) { /* ex.ParamName == \"source\" */ }","preventionTips":["Validate upstream factory/resolution results before chaining operators","Coalesce null sources to AsyncObservable.Empty<T>() when acceptable","Avoid nullable observable fields in pipelines"],"tags":["argumentnull","asyncrx","observable","null-check"],"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"}