{"record":{"id":"159c7ccc4936a841","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-onnext-asyncqueryableex","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'onNext')","messagePattern":"Value cannot be null\\. \\(Parameter 'onNext'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.cs","lineNumber":1076,"sourceCode":"                throw new ArgumentNullException(nameof(onError));\n            if (onCompleted == null)\n                throw new ArgumentNullException(nameof(onCompleted));\n\n            return source.Provider.CreateQuery<TSource>(Expression.Call(Do__TSource__4__1(typeof(TSource)), source.Expression, onNext, onError, onCompleted));\n        }\n\n        private static MethodInfo? s_Do__TSource__4__2;\n        \n        private static MethodInfo Do__TSource__4__2(Type TSource) =>\n            (s_Do__TSource__4__2 ??\n            (s_Do__TSource__4__2 = new Func<IAsyncQueryable<object>, Expression<Func<object, Task>>, Expression<Func<Exception, Task>>, Expression<Func<Task>>, IAsyncQueryable<object>>(Do<object>).GetMethodInfo()!.GetGenericMethodDefinition())).MakeGenericMethod(TSource);\n\n        public static IAsyncQueryable<TSource> Do<TSource>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, Task>> onNext, Expression<Func<Exception, Task>> onError, Expression<Func<Task>> 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\n            return source.Provider.CreateQuery<TSource>(Expression.Call(Do__TSource__4__2(typeof(TSource)), source.Expression, onNext, onError, onCompleted));\n        }\n\n        private static MethodInfo? s_Expand__TSource__2__0;\n        \n        private static MethodInfo Expand__TSource__2__0(Type TSource) =>\n            (s_Expand__TSource__2__0 ??\n            (s_Expand__TSource__2__0 = new Func<IAsyncQueryable<object>, Expression<Func<object, CancellationToken, ValueTask<IAsyncEnumerable<object>>>>, IAsyncQueryable<object>>(Expand<object>).GetMethodInfo()!.GetGenericMethodDefinition())).MakeGenericMethod(TSource);\n\n        public static IAsyncQueryable<TSource> Expand<TSource>(this IAsyncQueryable<TSource> source, Expression<Func<TSource, CancellationToken, ValueTask<IAsyncEnumerable<TSource>>>> selector)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));","sourceCodeStart":1058,"sourceCodeEnd":1094,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.cs#L1058-L1094","documentation":"ArgumentNullException thrown by the three-handler Do<TSource> extension when the onNext expression (Expression<Func<TSource, Task>>) is null. All handler arguments become nodes of the query expression tree sent to the provider, so onNext is validated immediately after source. The message names 'onNext'.","triggerScenarios":"Calling Do(source, null, onError, onCompleted) — usually when only error/completion logging was wired and the per-item handler was left null, or a handler selector returned null.","commonSituations":"Telemetry taps where item-level handling is optional; refactors that removed the body of onNext; mapping code from an observer interface where onNext was a no-op represented as null.","solutions":["Provide a no-op onNext: _ => Task.CompletedTask","Use a Do overload that takes fewer handlers if onNext is genuinely unneeded","Fix the handler factory to emit a completed-task lambda instead of null","Assert handler non-nullness at the point handlers are constructed"],"exampleFix":"// before\nquery.Do(null, OnError, OnDone);\n// after\nquery.Do(_ => Task.CompletedTask, OnError, OnDone);","handlingStrategy":"validation","validationCode":"if (onNext is null) onNext = _ => Task.CompletedTask;","typeGuard":"static bool HasNext<TSource>(Expression<Func<TSource, Task>>? h) => h is not null;","tryCatchPattern":"try { q = source.Do(onNext, onError, onCompleted); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"onNext\") { q = source.Do(_ => Task.CompletedTask, onError, onCompleted); }","preventionTips":["Supply no-op lambdas instead of null for unused handlers","Map observer interfaces so no-op handlers become Task.CompletedTask, not null","Code-review Do call sites for all three handler arguments"],"tags":["csharp","null-argument","expression-tree","do-operator"],"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"}