{"record":{"id":"03bb4da4aaeaafb1","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-contains","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":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Contains.cs","lineNumber":14,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// 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.Reactive.Linq\n{\n    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)));","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Contains.cs#L1-L32","documentation":"AsyncObservable.Contains<TSource>(source, element) throws ArgumentNullException naming 'source' when the observable sequence to search is null. The check runs eagerly so failure surfaces at the call site, not at subscription time.","triggerScenarios":"Calling Contains(null, someElement), often via method-chain syntax where the receiver expression evaluated to null: nullableSource.Contains(x).","commonSituations":"LINQ-style pipelines over observables produced by nullable factory methods, caches, or dictionary lookups that returned null; refactors introducing nullable sources.","solutions":["Pass a non-null IAsyncObservable<TSource>","Coalesce to AsyncObservable.Empty<TSource>() when the source may be absent","Fix the expression producing the source and check for null before chaining"],"exampleFix":"// before\nvar has = source.Contains(target); // source is null\n// after\nvar has = (source ?? AsyncObservable.Empty<int>()).Contains(target);","handlingStrategy":"validation","validationCode":"if (source is null) source = AsyncObservable.Empty<TSource>();","typeGuard":"public static bool IsNotNullSource<T>(IAsyncObservable<T>? s) => s is not null;","tryCatchPattern":"try { var has = source.Contains(element); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* handle absent source, e.g. return false */ }","preventionTips":["Enable nullable reference types to catch null receivers at compile time","Coalesce nullable sources to Empty<T>() before chaining operators","Null-check observables returned from factories and lookups"],"tags":["argument-null","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"}