{"record":{"id":"adead206aedeacbf","repo":"dotnet/reactive","slug":"nameof-oncompleted","errorCode":null,"errorMessage":"nameof(onCompleted)","messagePattern":"nameof\\(onCompleted\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs","lineNumber":244,"sourceCode":"        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (onCompleted == null)\n                throw new ArgumentNullException(nameof(onCompleted));\n\n            return Do(observer, Create<TSource>(_ => default, _ => default, onCompleted));\n        }\n\n        public static IAsyncObserver<TSource> Do<TSource>(IAsyncObserver<TSource> observer, Func<TSource, ValueTask> onNext, Func<Exception, ValueTask> onError, Func<ValueTask> onCompleted)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\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\n            return Do(observer, Create(onNext, onError, onCompleted));\n        }\n\n        public static IAsyncObserver<TSource> Do<TSource>(IAsyncObserver<TSource> observer, IObserver<TSource> witness)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (witness == null)\n                throw new ArgumentNullException(nameof(witness));\n\n            return Create<TSource>(\n                async x =>\n                {\n                    try\n                    {\n                        witness.OnNext(x);\n                    }","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs#L226-L262","documentation":"The full Do overload forwards onNext, onError, and onCompleted notifications to a witness observer, and the onCompleted callback must be non-null so completion signals can be witnessed. The library throws ArgumentNullException at argument-validation time when onCompleted is null. Nothing is subscribed yet when this fires.","triggerScenarios":"Calling Do<TSource>(observer, onNext, onError, onCompleted) (Do.cs:244) with null for the onCompleted argument.","commonSituations":"Developers assume completion handling is optional and omit it; code that synthesizes handlers from configuration where the completion hook is absent; copy-pasting a two-argument Do call and leaving the last argument empty.","solutions":["Pass a non-null onCompleted handler; use () => { } if completion should be ignored.","If no completion handling is needed, use the single-action overloads like Do(observer, onNext) instead.","Guard the callback variable for null before the call and substitute a no-op."],"exampleFix":"// before\nvar observer = Do(src, OnNext, OnError, null);\n// after\nvar observer = Do(src, OnNext, OnError, () => { });","handlingStrategy":"validation","validationCode":"if (onCompleted == null) onCompleted = () => { };\nvar observed = Do(observer, onNext, onError, onCompleted);","typeGuard":"bool IsValidHandler(Delegate d) => d is not null;","tryCatchPattern":"try\n{\n    var observed = Do(observer, onNext, onError, onCompleted);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"onCompleted\")\n{\n    var observed = Do(observer, onNext, onError, () => { });\n}","preventionTips":["Supply all three callbacks explicitly when using the full Do overload.","Use the smaller Do overloads when you only need some handlers.","Turn on nullable reference analysis to catch uninitialized delegate variables."],"tags":["argument-null","rx","do-operator","csharp"],"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"}