{"record":{"id":"49c7155eda900bff","repo":"dotnet/reactive","slug":"argumentnullexception-nameof-onerror","errorCode":null,"errorMessage":"ArgumentNullException(nameof(onError))","messagePattern":"ArgumentNullException\\(nameof\\(onError\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs","lineNumber":42,"sourceCode":"        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)));\n        }\n\n        public static IAsyncObservable<TSource> Do<TSource>(this IAsyncObservable<TSource> source, Action onCompleted)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (onCompleted == null)\n                throw new ArgumentNullException(nameof(onCompleted));\n\n            return Create(\n                source,\n                onCompleted,\n                static (source, onCompleted, target) => source.SubscribeSafeAsync(AsyncObserver.Do(target, onCompleted)));","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs#L24-L60","documentation":"The Do(source, onError) operator throws ArgumentNullException because the onError Action<Exception> side-effect callback is null. The library requires a real callback since Do exists only to invoke it.","triggerScenarios":"Calling source.Do(onError) with a null delegate, e.g. a conditional handler variable that was never assigned or a method parameter forwarded as null.","commonSituations":"Optional logging/error-handler fields that default to null; DI-injected handlers missing; passing a local that failed to initialize.","solutions":["Pass a non-null Action<Exception>, even a no-op such as _ => { }","Guard the handler with a default before composing: handler ?? DefaultHandler","Fix the producer that was supposed to supply the error handler"],"exampleFix":"// before\nAction<Exception> onError = config.ErrorHandler; // may be null\nvar res = src.Do(onError);\n// after\nvar res = src.Do(config.ErrorHandler ?? (ex => { }));","handlingStrategy":"validation","validationCode":"if (onError is null) onError = _ => { };\nvar res = source.Do(onError);","typeGuard":"static bool IsValidHandler(Action<Exception> h) => h is not null;","tryCatchPattern":"try { var res = source.Do(onError); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"onError\") { /* fall back to no-op handler */ }","preventionTips":["Default optional delegates to no-ops at declaration, not null","Use ?? to supply fallback handlers inline","Check DI/configuration wiring for handler dependencies","Enable nullable reference types"],"tags":["csharp","null-argument","callback","argument-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"}