{"record":{"id":"503498394fe14daf","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-503498","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/Min.cs","lineNumber":22,"sourceCode":"\nusing System.Collections.Generic;\n\nnamespace System.Linq\n{\n    public static partial class EnumerableEx\n    {\n#if !(REFERENCE_ASSEMBLY && NET6_0_OR_GREATER)\n        /// <summary>\n        /// Returns the minimum value in the enumerable sequence by using the specified comparer to compare values.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"comparer\">Comparer used to determine the minimum value.</param>\n        /// <returns>Minimum value in the sequence.</returns>\n        public static TSource Min<TSource>(this IEnumerable<TSource> source, IComparer<TSource> comparer)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (comparer == null)\n                throw new ArgumentNullException(nameof(comparer));\n\n            return MinByWithTies(source, x => x, comparer).First();\n        }\n#endif\n    }\n}\n","sourceCodeStart":4,"sourceCodeEnd":31,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/Min.cs#L4-L31","documentation":"The comparer-based Min<TSource>(source, comparer) extension validates that the source sequence is non-null and throws ArgumentNullException('source') first. Min needs a real sequence to scan; null is treated as a programming error rather than an empty result.","triggerScenarios":"Calling source.Min(comparer) where source is null — e.g. a method returning null instead of an empty sequence, an unassigned field, or the result of a failed lookup passed directly into Min.","commonSituations":"Repository/parse functions that return null instead of empty collections; nullable fields fed into extension methods;LINQ chains where an earlier custom operator produced null.","solutions":["Return/pass an empty sequence (Enumerable.Empty<T>()) instead of null.","Coalesce at the call site: (source ?? Enumerable.Empty<TSource>()).Min(comparer).","Fix the upstream producer so it never yields null sequences."],"exampleFix":"// before\nvar min = GetValues().Min(Comparer<int>.Default); // GetValues() returned null\n// after\nvar min = (GetValues() ?? Enumerable.Empty<int>()).Min(Comparer<int>.Default);","handlingStrategy":"validation","validationCode":"if (source == null) throw new InvalidOperationException(\"Sequence required.\");\nvar min = source.Min(comparer);","typeGuard":"static bool HasValues<T>(IEnumerable<T>? s) => s is not null;","tryCatchPattern":"try { min = source.Min(comparer); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { min = default; }","preventionTips":["Fix producers that return null instead of Enumerable.Empty<T>()","Coalesce with ?? Enumerable.Empty<T>() at call sites","Enable nullable reference types to surface null sequence flows"],"tags":["null-argument","linq","min","ix-interactive"],"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"}