{"record":{"id":"90e74a9a2b189d0d","repo":"dotnet/reactive","slug":"thrown-when-source-is-null-argumentnullexception-param-name-90e74a","errorCode":null,"errorMessage":"Thrown when source is null (ArgumentNullException, param name: source)","messagePattern":"Thrown when source is null \\(ArgumentNullException, param name: source\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/IgnoreElements.cs","lineNumber":20,"sourceCode":"// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Collections.Generic;\n\nnamespace System.Linq\n{\n    public static partial class EnumerableEx\n    {\n        /// <summary>\n        /// Ignores all elements in the source sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <returns>Source sequence without its elements.</returns>\n        public static IEnumerable<TSource> IgnoreElements<TSource>(this IEnumerable<TSource> source)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return IgnoreElementsCore(source);\n        }\n\n        private static IEnumerable<TSource> IgnoreElementsCore<TSource>(IEnumerable<TSource> source)\n        {\n            foreach (var _ in source)\n                ;\n\n            yield break;\n        }\n    }\n}\n","sourceCodeStart":2,"sourceCodeEnd":34,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/IgnoreElements.cs#L2-L34","documentation":"IgnoreElements enumerates a sequence and discards all of its elements, yielding nothing. Because the argument is validated eagerly in the public operator, passing a null source throws ArgumentNullException with paramName 'source' immediately rather than on MoveNext.","triggerScenarios":"Calling source.IgnoreElements() (extension method on IEnumerable<TSource>) where source is null, e.g. someQuery.IgnoreElements() when someQuery came from a null-returning factory or deserialization.","commonSituations":"Chaining Ix operators onto results of methods that may return null (configuration lookups, optional service calls); using IgnoreElements purely for side effects (e.g. draining an observable-like source) where the source variable was never assigned.","solutions":["Verify the source expression is non-null before invoking IgnoreElements; fix the producer so it returns an empty sequence instead of null.","Coalesce with ?? Enumerable.Empty<TSource>() at the call site.","If null signals a real problem, check and throw/log before calling, so the failure is attributable to the actual cause."],"exampleFix":"// before\nitems.IgnoreElements().Run(); // items is null when the cache missed\n// after\n(items ?? Enumerable.Empty<Item>()).IgnoreElements().Run();","handlingStrategy":"validation","validationCode":"if (source is null) source = Enumerable.Empty<TSource>();\nsource.IgnoreElements();","typeGuard":"static bool HasSource<T>(IEnumerable<T>? s) => s is not null;","tryCatchPattern":"try\n{\n    source.IgnoreElements();\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\")\n{\n    // source was null; log and continue with nothing to drain\n}","preventionTips":["Coalesce nullable sources with ?? Enumerable.Empty<T>() before chaining Ix operators","Fix producers to return empty sequences, never null, for 'no data'","Enable nullable reference types to catch unassigned source variables"],"tags":["argumentnull","linq","dotnet","ix-net"],"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"}