{"record":{"id":"a18922d7876d4664","repo":"dotnet/reactive","slug":"argumentnullexception-nameof-oncompleted","errorCode":null,"errorMessage":"ArgumentNullException(nameof(onCompleted))","messagePattern":"ArgumentNullException\\(nameof\\(onCompleted\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs","lineNumber":55,"sourceCode":"        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)));\n        }\n\n        public static IAsyncObservable<TSource> Do<TSource>(this IAsyncObservable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (onNext == null)\n                throw new ArgumentNullException(nameof(onNext));\n            if (onError == null)\n                throw new ArgumentNullException(nameof(onError));\n            if (onCompleted == null)\n                throw new ArgumentNullException(nameof(onCompleted));\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs#L37-L73","documentation":"This Do overload validates the onError callback passed as a side-effect observer action; null would make the tap unable to react to errors. The exception is thrown eagerly at operator-assembly time, not at subscription time. Fix: provide a non-null Action<Exception>, or use the Do overload that omits the error handler.","triggerScenarios":"Calling source.Do(onCompleted) with a null Action, e.g. an unassigned completion-handler field or a null method-group conversion failure.","commonSituations":"Optional teardown callbacks that default to null; forwarding an uninitialized parameter; configuration wiring that skipped the handler.","solutions":["Pass a real Action, using a no-op () => { } if no work is needed","Default the handler before composition: handler ?? (() => { })","Fix the configuration/DI wiring that should have provided the handler"],"exampleFix":"// before\nAction onCompleted = null;\nvar res = src.Do(onCompleted); // throws\n// after\nvar res = src.Do(onCompleted ?? (() => { }));","handlingStrategy":"validation","validationCode":"if (onCompleted is null) onCompleted = () => { };\nvar res = source.Do(onCompleted);","typeGuard":"static bool IsValidHandler(Action h) => h is not null;","tryCatchPattern":"try { var res = source.Do(onCompleted); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"onCompleted\") { /* fall back to no-op */ }","preventionTips":["Initialize delegate fields with no-op defaults rather than null","Use handler ?? (() => { }) at call sites","Verify configuration wiring assigns completion handlers","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"}