{"record":{"id":"22c4773a57071647","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-observer","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(observer));","messagePattern":"throw new ArgumentNullException\\(nameof\\(observer\\)\\);","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Retry.cs","lineNumber":55,"sourceCode":"                source,\n                retryCount,\n                static async (source, retryCount, observer) =>\n                {\n                    var (sink, inner) = AsyncObserver.Retry(observer, source, retryCount);\n\n                    var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(subscription, inner);\n                });\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static (IAsyncObserver<TSource>, IAsyncDisposable) Retry<TSource>(IAsyncObserver<TSource> observer, IAsyncObservable<TSource> source)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return Catch(observer, Repeat(source).GetEnumerator());\n        }\n\n        public static (IAsyncObserver<TSource>, IAsyncDisposable) Retry<TSource>(IAsyncObserver<TSource> observer, IAsyncObservable<TSource> source, int retryCount)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (retryCount < 0)\n                throw new ArgumentOutOfRangeException(nameof(retryCount));\n\n            return Catch(observer, Enumerable.Repeat(source, retryCount).GetEnumerator());\n        }\n    }","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Retry.cs#L37-L73","documentation":"The Retry operator requires a downstream observer to feed retried source notifications to. System.Reactive.Async throws ArgumentNullException immediately when the observer argument is null, before any subscription work starts, to fail fast instead of crashing later inside Catch/Repeat.","triggerScenarios":"Calling AsyncObserver.Retry<TSource>(null, someSource) — passing a null IAsyncObserver<TSource> as the first argument.","commonSituations":"Observers produced by a factory method or DI container that returned null; refactoring that removed observer construction but kept the Retry call; conditional observer wiring where a variable is unassigned on some paths.","solutions":["Pass a non-null IAsyncObserver<TSource> as the observer argument, e.g. create one via AsyncObserver.Create or chain from an existing pipeline.","Check the code that produces the observer — it is returning null; fix the factory/container registration.","If the observer is optional by design, guard the call site before invoking Retry."],"exampleFix":"// before\nvar (obs, disp) = AsyncObserver.Retry(observer, source); // observer is null\n// after\nif (observer == null) observer = AsyncObserver.Create<TSource>(...);\nvar (obs, disp) = AsyncObserver.Retry(observer, source);","handlingStrategy":"validation","validationCode":"if (observer == null) throw new InvalidOperationException(\"observer must be constructed before Retry\");\nvar (obs, disp) = AsyncObserver.Retry(observer, source);","typeGuard":"static bool HasObserver<TSource>(IAsyncObserver<TSource> o) => o is not null;","tryCatchPattern":"try { var (obs, disp) = AsyncObserver.Retry(observer, source); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\") { /* fix wiring; use default observer */ }","preventionTips":["Never store observers in nullable fields; create them inline where Retry is called.","Make observer factories non-nullable by contract (return throw-if-null).","Enable C# nullable reference types so null flow is caught at compile time."],"tags":["argument-null","async-rx","retry-operator","validation"],"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"}