{"record":{"id":"28a43f54fce81672","repo":"dotnet/reactive","slug":"source-ignoreelements","errorCode":null,"errorMessage":"source","messagePattern":"source","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/IgnoreElements.cs","lineNumber":12,"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\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TSource> IgnoreElements<TSource>(this 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.IgnoreElements(observer)));\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> IgnoreElements<TSource>(IAsyncObserver<TSource> observer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            return Where(observer, _ => false);\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/IgnoreElements.cs#L1-L29","documentation":"IgnoreElements(source) throws ArgumentNullException with paramName \"source\" when the source observable is null. This is a standard eager guard in AsyncRx operators, ensuring misuse is caught at the call site rather than during async subscription.","triggerScenarios":"Calling source.IgnoreElements() via a null extension-receiver, or AsyncObservable.IgnoreElements(null), e.g. when the observable came from a nullable field or failed lookup.","commonSituations":"Chaining operators on a value that is null because an earlier pipeline stage returned null (e.g. a cache or service locator miss), or a null-returning factory used in fluent chains.","solutions":["Ensure the source IAsyncObservable<TSource> is non-null before chaining; use AsyncObservable.Empty<TSource>() as a substitute.","Find the producer of the null observable (return null path in a factory/repository) and make it return an empty observable instead.","Add a null check or ?? fallback before calling IgnoreElements."],"exampleFix":"// before\nIObservable<int> src = GetSource(); // null\nvar ignored = src.IgnoreElements();\n// after\nIObservable<int> src = GetSource() ?? AsyncObservable.Empty<int>();\nvar ignored = src.IgnoreElements();","handlingStrategy":"validation","validationCode":"if (source is null) throw new ArgumentException(\"source must be non-null\");\n// or: source ??= AsyncObservable.Empty<TSource>();","typeGuard":"static bool HasSource<TSource>(IAsyncObservable<TSource> s) => s is not null;","tryCatchPattern":"try { var ignored = src.IgnoreElements(); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* repair or substitute source */ }","preventionTips":["Never let producer methods return null observables","Use ?? AsyncObservable.Empty<T>() in fluent chains","Enable nullable reference types to catch null flows at compile time"],"tags":["argument-null","operators","reactive"],"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"}