{"record":{"id":"fe9128502416d1e6","repo":"dotnet/reactive","slug":"observer-ignoreelements","errorCode":null,"errorMessage":"observer","messagePattern":"observer","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/IgnoreElements.cs","lineNumber":23,"sourceCode":"namespace 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":5,"sourceCodeEnd":29,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/IgnoreElements.cs#L5-L29","documentation":"AsyncObserver.IgnoreElements(observer) throws ArgumentNullException with paramName \"observer\" when the downstream IAsyncObserver<TSource> is null. This is the observer-level API used when building custom observers; it composes Where(observer, _ => false) and must receive a valid downstream observer.","triggerScenarios":"Calling AsyncObserver.IgnoreElements(null) while hand-rolling a custom observer pipeline, or passing a null observer from a custom SubscribeAsync implementation.","commonSituations":"Writing a custom operator where the downstream observer comes from a nullable constructor parameter or an unassigned field in a custom IAsyncObservable implementation.","solutions":["Pass the actual downstream IAsyncObserver<TSource> received in SubscribeSafeAsync/SubscribeAsync to AsyncObserver.IgnoreElements.","Fix the custom observable/observer implementation that stores or forwards a null observer.","Add an ArgumentNullException guard in your own operator so the failure is attributed correctly."],"exampleFix":"// before\npublic IAsyncDisposable SubscribeAsync(IAsyncObserver<int> observer)\n    => AsyncObserver.IgnoreElements(_observer); // _observer not initialized\n// after\npublic IAsyncDisposable SubscribeAsync(IAsyncObserver<int> observer)\n    => source.SubscribeSafeAsync(AsyncObserver.IgnoreElements(observer));","handlingStrategy":"validation","validationCode":"if (observer is null) throw new ArgumentNullException(nameof(observer));\n// before calling AsyncObserver.IgnoreElements(observer)","typeGuard":"static bool HasObserver<TSource>(IAsyncObserver<TSource> o) => o is not null;","tryCatchPattern":"try { var o = AsyncObserver.IgnoreElements(observer); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\") { /* fix observer wiring */ }","preventionTips":["Always forward the observer parameter from SubscribeAsync, not cached fields","Add ArgumentNullException guards in custom operators","Initialize observer fields in constructors, not lazily"],"tags":["argument-null","observer","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"}