{"record":{"id":"40b0647aee946ba6","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-getenumerator","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'getEnumerator')","messagePattern":"Value cannot be null\\. \\(Parameter 'getEnumerator'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/Create.cs","lineNumber":21,"sourceCode":"// See the LICENSE file in the project root for more information. \n\nusing System.Collections;\nusing System.Collections.Generic;\n\nnamespace System.Linq\n{\n    public static partial class EnumerableEx\n    {\n        /// <summary>\n        /// Creates an enumerable sequence based on an enumerator factory function.\n        /// </summary>\n        /// <typeparam name=\"TResult\">Result sequence element type.</typeparam>\n        /// <param name=\"getEnumerator\">Enumerator factory function.</param>\n        /// <returns>Sequence that will invoke the enumerator factory upon a call to GetEnumerator.</returns>\n        public static IEnumerable<TResult> Create<TResult>(Func<IEnumerator<TResult>> getEnumerator)\n        {\n            if (getEnumerator == null)\n                throw new ArgumentNullException(nameof(getEnumerator));\n\n            return new AnonymousEnumerable<TResult>(getEnumerator);\n        }\n\n        /// <summary>\n        /// Creates an enumerable sequence based on an asynchronous method that provides a yielder.\n        /// </summary>\n        /// <typeparam name=\"T\">Result sequence element type.</typeparam>\n        /// <param name=\"create\">\n        /// Delegate implementing an asynchronous method that can use the specified yielder to yield return\n        /// values.\n        /// </param>\n        /// <returns>Sequence that will use the asynchronous method to obtain its elements.</returns>\n        public static IEnumerable<T> Create<T>(Action<IYielder<T>> create)\n        {\n            if (create == null)\n                throw new ArgumentNullException(nameof(create));\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/Create.cs#L3-L39","documentation":"System.Interactive's Create operator builds an IEnumerable from a factory delegate that produces an IEnumerator on each enumeration. The library eagerly validates its arguments and throws ArgumentNullException when the getEnumerator factory is null, so the failure surfaces at call time rather than at enumeration time.","triggerScenarios":"Calling EnumerableEx.Create<TResult>(null) directly, or calling Memoize/Publish/Share with a null source or a null enumerator-factory argument that they forward to Create.","commonSituations":"A factory method returning null instead of a delegate (e.g. a switch statement that misses a default branch), a config-driven delegate lookup that resolves to null, or passing an uninitialized method-group variable.","solutions":["Ensure the delegate passed to Create (or to Memoize/Publish/Share whose argument is forwarded) is non-null before calling","Fix whatever produces the null factory — e.g. a factory dictionary or switch that returns null for the given key","If the factory is conditionally unavailable, throw a more descriptive exception or fall back to an empty sequence","Wrap the call in a null-coalescing expression: Create(() => ?? throw new InvalidOperationException(...))"],"exampleFix":"// before\nvar seq = EnumerableEx.Create(getEnumerator); // getEnumerator is null\n// after\nif (getEnumerator == null)\n    throw new InvalidOperationException(\"No enumerator factory configured for this source.\");\nvar seq = EnumerableEx.Create(getEnumerator);","handlingStrategy":"validation","validationCode":"if (getEnumerator == null)\n    throw new ArgumentNullException(nameof(getEnumerator));\n// or defensively:\nvar factory = getEnumerator ?? throw new ArgumentException(\"Enumerator factory must be provided.\");\nvar seq = EnumerableEx.Create(factory);","typeGuard":"static bool IsValidFactory<T>(Func<IEnumerator<T>> factory) => factory is not null;","tryCatchPattern":"try\n{\n    var seq = EnumerableEx.Create(getEnumerator);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"getEnumerator\")\n{\n    // log and supply a default factory or rethrow with context\n}","preventionTips":["Never return null delegates from factory-lookup code; throw or return a default instead","Use throw expressions in switch/map lookups so missing keys fail loudly","Enable nullable reference types so unassigned delegate variables are flagged at compile time"],"tags":["null-argument","csharp","ix-net","argument-validation"],"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"}