{"record":{"id":"7ba8ead9206832f4","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-comparer","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'comparer')","messagePattern":"Value cannot be null\\. \\(Parameter 'comparer'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Contains.cs","lineNumber":27,"sourceCode":"    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<bool> Contains<TSource>(this IAsyncObservable<TSource> source, TSource element)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return CreateAsyncObservable<bool>.From(\n                source,\n                element,\n                static (source, element, observer) => source.SubscribeSafeAsync(AsyncObserver.Contains(observer, element)));\n        }\n\n        public static IAsyncObservable<bool> Contains<TSource>(this IAsyncObservable<TSource> source, TSource element, IEqualityComparer<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<bool>.From(\n                source,\n                (element, comparer),\n                static (source, state, observer) => source.SubscribeSafeAsync(AsyncObserver.Contains(observer, state.element, state.comparer)));\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> Contains<TSource>(IAsyncObserver<bool> observer, TSource element)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            return Contains(observer, element, EqualityComparer<TSource>.Default);\n        }\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Contains.cs#L9-L45","documentation":"AsyncObservable.Contains<TSource>(source, element, comparer) throws ArgumentNullException naming 'comparer' when the IEqualityComparer<TSource> is null. If you don't need custom equality, call the two-argument Contains overload which uses the default equality comparison.","triggerScenarios":"Passing an explicitly null comparer: source.Contains(element, null); commonly a comparer resolved from DI/config or a static field that was null.","commonSituations":"Config-driven comparison strategies where the configured comparer type failed to instantiate; refactors where a default comparer field was removed or renamed.","solutions":["Pass a non-null IEqualityComparer<TSource> (e.g. EqualityComparer<T>.Default) or drop the comparer argument to use the default overload","Ensure DI/config resolution of the comparer actually returns an instance","Fall back to EqualityComparer<T>.Default when the resolved comparer is null"],"exampleFix":"// before\nvar has = source.Contains(target, comparer); // comparer is null\n// after\nvar has = source.Contains(target, comparer ?? EqualityComparer<string>.Default);","handlingStrategy":"validation","validationCode":"var safeComparer = comparer ?? EqualityComparer<TSource>.Default;","typeGuard":"public static bool HasComparer<T>(IEqualityComparer<T>? c) => c is not null;","tryCatchPattern":"try { var has = source.Contains(element, comparer); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"comparer\") { /* fall back to EqualityComparer<T>.Default or the 2-arg overload */ }","preventionTips":["Use the two-argument Contains when default equality suffices","Default unresolved comparers to EqualityComparer<T>.Default","Validate DI/config-provided comparers resolve to instances"],"tags":["argument-null","comparer","contains","async-rx"],"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"}