{"record":{"id":"6b3272fe4b57bdd2","repo":"dotnet/reactive","slug":"argumentnullexception-nameof-onnext","errorCode":null,"errorMessage":"ArgumentNullException(nameof(onNext))","messagePattern":"ArgumentNullException\\(nameof\\(onNext\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs","lineNumber":29,"sourceCode":"        public static IAsyncObservable<TSource> Do<TSource>(this IAsyncObservable<TSource> source, IObserver<TSource> observer)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            return Create(\n                source,\n                observer,\n                static (source, observer, target) => source.SubscribeSafeAsync(AsyncObserver.Do(target, observer)));\n        }\n\n        public static IAsyncObservable<TSource> Do<TSource>(this IAsyncObservable<TSource> source, Action<TSource> onNext)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (onNext == null)\n                throw new ArgumentNullException(nameof(onNext));\n\n            return Create(\n                source,\n                onNext,\n                static (source, onNext, target) => source.SubscribeSafeAsync(AsyncObserver.Do(target, onNext)));\n        }\n\n        public static IAsyncObservable<TSource> Do<TSource>(this IAsyncObservable<TSource> source, Action<Exception> onError)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (onError == null)\n                throw new ArgumentNullException(nameof(onError));\n\n            return Create(\n                source,\n                onError,\n                static (source, onError, target) => source.SubscribeSafeAsync(AsyncObserver.Do(target, onError)));","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs#L11-L47","documentation":"Do<TSource>(this IAsyncObservable<TSource> source, Action<TSource> onNext) throws ArgumentNullException when the onNext delegate is null. onNext is invoked for every element flowing through the tap; without it the overload is meaningless, so null is rejected at composition time rather than at the first notification.","triggerScenarios":"Calling source.Do(null) or AsyncObservable.Do(source, null) with the Action<TSource> overload; passing an Action variable that was never assigned.","commonSituations":"Logging action injected from settings that was not configured; a nullable static Action field; a refactor from the IObserver overload leaving the delegate unset.","solutions":["Pass a non-null action, e.g. x => Console.WriteLine(x).","If the tap is optional, skip Do when the action is null: action != null ? source.Do(action) : source.","Ensure configuration/DI providing the callback is set up."],"exampleFix":"// before\nsource.Do(settings.OnNextHandler); // null when not configured\n// after\nvar action = settings.OnNextHandler ?? throw new InvalidOperationException(\"onNext handler not configured\");\nvar tapped = source.Do(action);","handlingStrategy":"validation","validationCode":"if (onNext is null) throw new InvalidOperationException(\"onNext callback required\");\nvar tapped = source.Do(onNext);","typeGuard":"static bool IsValidAction<T>(Action<T>? a) => a is not null;","tryCatchPattern":"try { var tapped = source.Do(onNext); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"onNext\") { /* supply a logging/side-effect callback */ }","preventionTips":["Pass inline lambdas for ad-hoc side effects instead of nullable delegate fields.","Make optional taps explicit with conditional composition rather than null.","Validate configured callbacks at startup and fail fast with clear messages."],"tags":["argument-null","delegate","do-operator","async-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"}