{"record":{"id":"e76dced9843ca72c","repo":"dotnet/reactive","slug":"nameof-onnext","errorCode":null,"errorMessage":"nameof(onNext)","messagePattern":"nameof\\(onNext\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs","lineNumber":240,"sourceCode":"            return Do(observer, Create<TSource>(_ => default, onError, () => default));\n        }\n\n        public static IAsyncObserver<TSource> Do<TSource>(IAsyncObserver<TSource> observer, Func<ValueTask> onCompleted)\n        {\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                {","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Do.cs#L222-L258","documentation":"The full Do(observer, onNext, onError, onCompleted) overload throws ArgumentNullException when the onNext callback is null. All four arguments are validated in order (observer, onNext, onError, onCompleted) at composition time; onNext fires for every element, so it cannot be null.","triggerScenarios":"Calling AsyncObserver.Do<TSource>(validObserver, null, onError, onCompleted) — null Func<TSource, ValueTask> in the four-argument overload.","commonSituations":"Building handlers from configuration where the per-element handler is optional and left null; passing method groups conditionally compiled or feature-flagged off; a nullable delegate field assigned only in one branch of an if/else.","solutions":["Supply a non-null onNext handler; if per-element side effects are unnecessary, pass `_ => default`.","Use the null-coalescing idiom `onNext ?? (_ => default)` for optional handlers.","Reorder code so the handler is assigned (or defaulted) before Do is invoked; add a debug assert for early detection."],"exampleFix":"// before\nvar obs = AsyncObserver.Do<int>(sink, flags.LogElements ? LogAsync : null, onError, onCompleted);\n\n// after\nvar obs = AsyncObserver.Do<int>(sink, flags.LogElements ? LogAsync : _ => default, onError, onCompleted);","handlingStrategy":"validation","validationCode":"onNext ??= _ => default;\nvar result = AsyncObserver.Do(source, observer, onNext, onError, onCompleted);","typeGuard":"static bool HasOnNext<T>(Func<T, ValueTask>? h) => h is not null;","tryCatchPattern":"try\n{\n    var obs = AsyncObserver.Do(source, observer, onNext, onError, onCompleted);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"onNext\")\n{\n    log.LogError(ex, \"onNext was null in full Do overload\");\n    obs = AsyncObserver.Do(source, observer, _ => default, onError, onCompleted);\n}","preventionTips":["Default per-element handlers to `_ => default` when optional","Pass lambdas inline rather than via nullable delegate variables","Guard feature-flag-selected handlers before composing","Enable nullable reference types to surface unassigned delegates at compile time"],"tags":["null-argument","argument-validation","async-reactive"],"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"}