{"record":{"id":"69f73f22429fc0fe","repo":"dotnet/reactive","slug":"iteratormethod","errorCode":null,"errorMessage":"iteratorMethod","messagePattern":"iteratorMethod","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/ObservableEx.cs","lineNumber":36,"sourceCode":"#pragma warning disable IDE0044 // Make readonly: since 3rd party code reflects for this, we shouldn't pretend it won't change\n        private static IQueryLanguageEx s_impl = QueryServices.GetQueryImpl<IQueryLanguageEx>(new QueryLanguageEx());\n#pragma warning restore IDE1006, IDE0044 // Naming Styles, Make readonly\n\n        #region Create\n\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        /// <typeparam name=\"TResult\">The type of the elements in the produced sequence.</typeparam>\n        /// <param name=\"iteratorMethod\">Iterator method that produces elements in the resulting sequence by calling the given observer.</param>\n        /// <returns>An observable sequence obtained by running the iterator and returning the elements that were sent to the observer.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"iteratorMethod\"/> is null.</exception>\n        [Experimental]\n        public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, IEnumerable<IObservable<object>>> iteratorMethod)\n        {\n            if (iteratorMethod == null)\n            {\n                throw new ArgumentNullException(nameof(iteratorMethod));\n            }\n\n            return s_impl.Create(iteratorMethod);\n        }\n\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=\"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\"><paramref name=\"iteratorMethod\"/> is null.</exception>\n        [Experimental]\n        public static IObservable<Unit> Create(Func<IEnumerable<IObservable<object>>> iteratorMethod)\n        {\n            if (iteratorMethod == null)\n            {\n                throw new ArgumentNullException(nameof(iteratorMethod));\n            }","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/ObservableEx.cs#L18-L54","documentation":"ObservableEx.Create<TResult>(Func<IObserver<TResult>, IEnumerable<IObservable<object>>>) is an experimental factory that builds an observable from an iterator-style method. It validates its delegate eagerly and throws ArgumentNullException when iteratorMethod is null. Fail-fast keeps the null reference from surfacing only at Subscribe time.","triggerScenarios":"Passing a null Func to Create, typically a method-group or lambda variable that was never assigned, or a conditional factory returning null.","commonSituations":"Optional behavior hooks (logging/telemetry generators) that default to null, reflection-based lookups (GetMethod/Delegate.CreateDelegate) returning null, refactoring away a local function but leaving the null variable.","solutions":["Ensure the iteratorMethod Func is assigned before calling Create","If the delegate is optional, branch to a non-experimental default observable (Observable.Empty or Observable.Defer) instead of passing null","Check reflection or config-driven delegate construction for silent null results"],"exampleFix":"// before\nFunc<IObserver<int>, IEnumerable<IObservable<object>>> gen = GetGenerator(); // may be null\nvar obs = ObservableEx.Create(gen);\n// after\nvar gen = GetGenerator();\nvar obs = gen != null ? ObservableEx.Create(gen) : Observable.Empty<int>();","handlingStrategy":"validation","validationCode":"if (iteratorMethod == null) throw new ArgumentNullException(nameof(iteratorMethod), \"Create requires a generator delegate.\");","typeGuard":"bool IsValidGenerator<TResult>(Func<IObserver<TResult>, IEnumerable<IObservable<object>>> f) => f is not null;","tryCatchPattern":"try { var obs = ObservableEx.Create(iteratorMethod); }\ncatch (ArgumentNullException ex) { log.Error(\"Generator delegate was null\", ex); }","preventionTips":["Initialize delegate fields with a default no-op generator","Verify reflection-based delegate lookups succeed before use","Treat optional generators as nullable and branch instead of passing null"],"tags":["csharp","null-argument","experimental-api","reactive-extensions"],"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"}