{"record":{"id":"d194b9422eb85f93","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-comparer-min","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'comparer')","messagePattern":"Value cannot be null\\. \\(Parameter 'comparer'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Min.cs","lineNumber":25,"sourceCode":"\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TSource> Min<TSource>(IAsyncObservable<TSource> source)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return Create(source, static (source, observer) => source.SubscribeSafeAsync(AsyncObserver.Min(observer)));\n        }\n\n        public static IAsyncObservable<TSource> Min<TSource>(IAsyncObservable<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 CreateAsyncObservable<TSource>.From(\n                source,\n                comparer,\n                static (source, comparer, observer) => source.SubscribeSafeAsync(AsyncObserver.Min(observer, comparer)));\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> Min<TSource>(IAsyncObserver<TSource> observer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            return Min(observer, Comparer<TSource>.Default);\n        }\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Min.cs#L7-L43","documentation":"The two-argument Min overload requires a non-null IComparer<TSource>. The library throws ArgumentNullException with Parameter 'comparer' when null is supplied, because every element comparison during aggregation depends on it. Pass Comparer<T>.Default (or use the single-argument overload) when no custom comparer is needed.","triggerScenarios":"Calling Min(source, comparer) with comparer = null, e.g. a comparer parameter forwarded from a caller that passed null.","commonSituations":"Wrapping APIs that accept an optional IComparer<T> and forwarding it unvalidated to Min; returning null from a comparer-provider factory; forgetting Comparer<T>.Default in generic helper code.","solutions":["Pass a concrete comparer or Comparer<TSource>.Default instead of null","Use the single-argument Min(source) overload which defaults to Comparer<TSource>.Default","Validate the comparer at your API boundary before forwarding it"],"exampleFix":"// before\nvar result = AsyncObservable.Min(source, null);\n// after\nvar result = AsyncObservable.Min(source, Comparer<MyType>.Default);","handlingStrategy":"validation","validationCode":"if (source == null) throw new ArgumentNullException(nameof(source));\nif (comparer == null) comparer = Comparer<TSource>.Default;","typeGuard":"bool IsValidComparer<T>(IComparer<T> c) => c is not null;","tryCatchPattern":"try { var result = AsyncObservable.Min(source, comparer); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"comparer\") { /* pass Comparer<T>.Default */ }","preventionTips":["Use the single-argument Min overload unless a custom comparer is truly needed","Give optional comparer parameters a Comparer<T>.Default default instead of null","Validate comparer parameters at your public API boundary"],"tags":["csharp","null-argument","icomparer"],"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"}