{"record":{"id":"690a633797beeee8","repo":"dotnet/reactive","slug":"observer-select","errorCode":null,"errorMessage":"observer","messagePattern":"observer","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Select.cs","lineNumber":69,"sourceCode":"        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (selector == null)\n                throw new ArgumentNullException(nameof(selector));\n\n            return CreateAsyncObservable<TResult>.From(\n                source,\n                selector,\n                static (source, selector, observer) => source.SubscribeSafeAsync(AsyncObserver.Select(observer, selector)));\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> Select<TSource, TResult>(IAsyncObserver<TResult> observer, Func<TSource, TResult> selector)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (selector == null)\n                throw new ArgumentNullException(nameof(selector));\n\n            return Create<TSource>(\n                async x =>\n                {\n                    TResult res;\n\n                    try\n                    {\n                        res = selector(x);\n                    }\n                    catch (Exception ex)\n                    {\n                        await observer.OnErrorAsync(ex).ConfigureAwait(false);\n                        return;\n                    }\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Select.cs#L51-L87","documentation":"AsyncObserver.Select (sync, non-indexed) validates its downstream IAsyncObserver<TResult> and throws ArgumentNullException named 'observer' when it is null. This guards the internal operator composition path so a null downstream observer is rejected immediately.","triggerScenarios":"Calling AsyncObserver.Select<TSource,TResult>(null, x => result) directly, usually when composing custom operators or wiring observers manually.","commonSituations":"Custom operator builders that pass a not-yet-created observer; refactoring where the downstream observer variable became null; testing operator internals with null observers.","solutions":["Always pass a real IAsyncObserver<TResult>, e.g. one obtained from Create or a downstream operator","Assert non-null upstream before composing: ArgumentNullException.ThrowIfNull(observer)","If downstream may be absent, use a no-op observer implementation instead of null"],"exampleFix":"// before\nvar obs = AsyncObserver.Select<int, int>(null, x => x * 2);\n// after\nvar downstream = AsyncObserver.Create<int>(async x => Console.WriteLine(x));\nvar obs = AsyncObserver.Select<int, int>(downstream, x => x * 2);","handlingStrategy":"validation","validationCode":"if (observer is null) throw new ArgumentNullException(nameof(observer));","typeGuard":"static bool IsValidObserver<T>(IAsyncObserver<T>? o) => o is not null;","tryCatchPattern":"try { var obs = AsyncObserver.Select<int, int>(downstream, x => x); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\") { /* create or substitute downstream observer */ }","preventionTips":["Build observer pipelines top-down so downstream exists before composition","Use AsyncObserver.Create to construct observers in tests instead of passing null","Assert non-null observer parameters in custom operator helpers"],"tags":["csharp","null-argument","rx","observer"],"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"}