{"record":{"id":"fbfb7fe5542b4e28","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-iteratormethod","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(iteratorMethod))","messagePattern":"throw new ArgumentNullException\\(nameof\\(iteratorMethod\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs","lineNumber":967,"sourceCode":"            );\n        }\n\n#if !STABLE\n        /// <summary>\n        /// Subscribes to each observable sequence returned by the iteratorMethod in sequence and produces a Unit value on the resulting sequence for each step of the iteration.\n        /// </summary>\n        /// <param name=\"provider\">Query provider used to construct the <see cref=\"IQbservable{T}\"/> data source.</param>\n        /// <param name=\"iteratorMethod\">Iterator method that drives the resulting observable sequence.</param>\n        /// <returns>An observable sequence obtained by running the iterator and returning Unit values for each iteration step.</returns>\n        /// <exception cref=\"ArgumentNullException\">\n        /// <paramref name=\"iteratorMethod\" /> is null.</exception>\n        [Experimental]\n        public static IQbservable<Unit> Create(this IQbservableProvider provider, Expression<Func<IEnumerable<IObservable<object>>>> iteratorMethod)\n        {\n            if (provider == null)\n                throw new ArgumentNullException(nameof(provider));\n            if (iteratorMethod == null)\n                throw new ArgumentNullException(nameof(iteratorMethod));\n\n            return provider.CreateQuery<Unit>(\n                Expression.Call(\n                    null,\n                    new Func<IQbservableProvider, Expression<Func<IEnumerable<IObservable<object>>>>, IQbservable<Unit>>(Create).Method,\n                    Expression.Constant(provider, typeof(IQbservableProvider)),\n                    iteratorMethod\n                )\n            );\n        }\n#endif\n\n#if !STABLE\n        /// <summary>\n        /// Subscribes to each observable sequence returned by the iteratorMethod in sequence and returns the observable sequence of values sent to the observer given to the iteratorMethod.\n        /// </summary>\n        /// <param name=\"provider\">Query provider used to construct the <see cref=\"IQbservable{T}\"/> data source.</param>\n        /// <typeparam name=\"TResult\">The type of the elements in the produced sequence.</typeparam>","sourceCodeStart":949,"sourceCodeEnd":985,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/QbservableEx.Homoicon.cs#L949-L985","documentation":"QbservableEx.Create(provider, iteratorMethod) requires the generator method as an Expression<Func<IEnumerable<IObservable<object>>>> so it can be serialized into the query expression tree. A null iteratorMethod throws ArgumentNullException named 'iteratorMethod'. The expression is needed because qbservable queries are transmitted as expression trees, not compiled delegates.","triggerScenarios":"Calling Qbservable.Create(provider, null) — usually when the iterator lambda was built conditionally, stored in a nullable variable, or produced by reflection/factory code that returned null.","commonSituations":"Building iterator methods dynamically and passing an unassigned variable; refactoring where the lambda was removed but the call remained; conditional query construction where only some branches define the iterator.","solutions":["Supply a real expression lambda, e.g. () => new[] { Observable.Return(1) } typed as IEnumerable<IObservable<object>>","If the iterator is optional, branch: skip Create entirely when iteratorMethod is null","Fix the factory/reflective builder that returned a null expression"],"exampleFix":"// before\nQbservable.Create(provider, iteratorMethod); // iteratorMethod is null\n// after\nExpression<Func<IEnumerable<IObservable<object>>>> iteratorMethod =\n    () => new[] { Observable.Return((object)42) };\nQbservable.Create(provider, iteratorMethod);","handlingStrategy":"validation","validationCode":"if (iteratorMethod == null)\n    throw new InvalidOperationException(\"iteratorMethod expression is required for Qbservable.Create\");","typeGuard":"bool HasIterator(Expression<Func<IEnumerable<IObservable<object>>>> m) => m is not null;","tryCatchPattern":"try\n{\n    var query = Qbservable.Create(provider, iteratorMethod);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"iteratorMethod\")\n{\n    logger.LogError(ex, \"Iterator expression was null\");\n}","preventionTips":["Always pass literal expression lambdas to Create, not nullable variables","Remember Qbservable APIs require Expression<>, not plain Func<>","Skip the Create call entirely when the iterator is not defined"],"tags":["argumentnull","rx","qbservable","expression-tree"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}