{"record":{"id":"b35edac6b2474f76","repo":"dotnet/reactive","slug":"thrown-when-source-is-null-argumentnullexception-param-name-b35eda","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/IsEmpty.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        /// Determines whether an enumerable sequence is empty.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <returns>true if the sequence is empty; false otherwise.</returns>\n        public static bool IsEmpty<TSource>(this IEnumerable<TSource> source)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return !source.Any();\n        }\n    }\n}\n","sourceCodeStart":2,"sourceCodeEnd":26,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/IsEmpty.cs#L2-L26","documentation":"IsEmpty checks whether a sequence contains no elements by delegating to Any(). The operator validates its argument eagerly, so a null source throws ArgumentNullException with paramName 'source' at the call site rather than during evaluation.","triggerScenarios":"Calling source.IsEmpty() where source is null, e.g. bool empty = ParseList(xml).IsEmpty() when ParseList can return null.","commonSituations":"Guard checks written as if (data.IsEmpty()) where data came from an API returning null for 'no data'; migrating code from LINQ's Any() (which also throws on null) to Ix's IsEmpty without adding null handling.","solutions":["Null-check the source first: if (data != null && data.IsEmpty()).","Coalesce to an empty sequence: (data ?? []).IsEmpty().","Fix the upstream producer to return an empty collection instead of null for the 'none' case."],"exampleFix":"// before\nif (results.IsEmpty()) ShowEmpty(); // results may be null\n// after\nif (results is not null && results.IsEmpty()) ShowEmpty();","handlingStrategy":"validation","validationCode":"bool empty = source is not null && source.IsEmpty();","typeGuard":"static bool IsNullOrEmpty<T>(IEnumerable<T>? s) => s is null || s.IsEmpty();","tryCatchPattern":"try\n{\n    var empty = source.IsEmpty();\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\")\n{\n    var empty = true; // treat null as empty\n}","preventionTips":["Write null-safe emptiness checks as a helper (IsNullOrEmpty)","Treat null and empty distinctly at the domain boundary, then normalize to empty","Don't feed nullable API results straight into IsEmpty/Any-style guards"],"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"}