{"record":{"id":"1eab5dcc0cf0ee4e","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-observer-fromasyncpattern","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'observer')","messagePattern":"Value cannot be null\\. \\(Parameter 'observer'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/FromAsyncPattern.Generated.cs","lineNumber":740,"sourceCode":"                    AsyncObserver.FromAsyncPattern(subject, begin, end, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);\n                }\n                catch (Exception ex)\n                {\n                    return Throw<Unit>(ex);\n                }\n\n                return subject.AsAsyncObservable();\n            };\n        }\n\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncResult FromAsyncPattern<TResult>(IAsyncObserver<TResult> observer, Func<AsyncCallback, object, IAsyncResult> begin, Func<IAsyncResult, TResult> end)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (begin == null)\n                throw new ArgumentNullException(nameof(begin));\n            if (end == null)\n                throw new ArgumentNullException(nameof(end));\n\n            return begin(async iar =>\n            {\n                TResult result;\n\n                try\n                {\n                    result = end(iar);\n                }\n                catch (Exception ex)\n                {\n                    await observer.OnErrorAsync(ex).ConfigureAwait(false);\n                    return;\n                }","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/FromAsyncPattern.Generated.cs#L722-L758","documentation":"This ArgumentNullException comes from AsyncObserver.FromAsyncPattern<TResult>(observer, begin, end) when the 'observer' parameter (IAsyncObserver<TResult> that receives the result or error) is null. This overload pushes the APM completion into an observer, so a null observer would make results undeliverable and is rejected immediately.","triggerScenarios":"Calling AsyncObserver.FromAsyncPattern<TResult>(null, begin, end) — typically when wiring an observer from a pipeline that supplied null.","commonSituations":"Building custom async observables where the observer comes from SubscribeSafe/lambda plumbing that returned null; ordering mistakes when refactoring operator internals.","solutions":["Pass the actual IAsyncObserver<TResult> instance you received (e.g. the one handed to your Subscribe/Run method).","Verify the variable holding the observer is assigned before calling FromAsyncPattern.","If the observer is optional in your design, guard with a null check and fail with a descriptive error."],"exampleFix":"// before\nAsyncObserver.FromAsyncPattern<int>(null, cb => svc.BeginOp(cb, null), ar => svc.EndOp(ar));\n// after\nIAsyncObserver<int> observer = GetObserver(); // must be non-null\nAsyncObserver.FromAsyncPattern(observer, cb => svc.BeginOp(cb, null), ar => svc.EndOp(ar));","handlingStrategy":"validation","validationCode":"if (observer is null) throw new ArgumentNullException(nameof(observer));\nif (begin is null || end is null) throw new ArgumentException(\"begin/end required\");\nAsyncObserver.FromAsyncPattern(observer, begin, end);","typeGuard":"static bool IsValidObserverPattern<TResult>(IAsyncObserver<TResult> observer,\n    Func<AsyncCallback, object, IAsyncResult> begin, Func<IAsyncResult, TResult> end)\n    => observer is not null && begin is not null && end is not null;","tryCatchPattern":"try { AsyncObserver.FromAsyncPattern(observer, begin, end); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\")\n{\n    // observer pipeline produced null; inspect upstream Subscribe wiring\n}","preventionTips":["Always pass the observer instance received from the Subscribe/Run callback, never a recomputed one.","Null-check the observer at the top of custom operator implementations.","Avoid service-locator lookups that can return null for observers.","Add Debug.Assert(observer != null) in operator internals during development."],"tags":["csharp","argumentnull","observer","apm"],"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"}