{"record":{"id":"34f613d234ce00c5","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-oncompletedasync-34f613","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'onCompletedAsync')","messagePattern":"Value cannot be null\\. \\(Parameter 'onCompletedAsync'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/AsyncObserver.cs","lineNumber":42,"sourceCode":"        {\n            if (onNextAsync == null)\n                throw new ArgumentNullException(nameof(onNextAsync));\n            if (onErrorAsync == null)\n                throw new ArgumentNullException(nameof(onErrorAsync));\n            if (onCompletedAsync == null)\n                throw new ArgumentNullException(nameof(onCompletedAsync));\n\n            return new AsyncObserver<T>(onNextAsync, onErrorAsync, onCompletedAsync);\n        }\n\n        internal static IAsyncObserver<T> CreateUnsafe<T>(Func<T, ValueTask> onNextAsync, Func<Exception, ValueTask> onErrorAsync, Func<ValueTask> onCompletedAsync)\n        {\n            if (onNextAsync == null)\n                throw new ArgumentNullException(nameof(onNextAsync));\n            if (onErrorAsync == null)\n                throw new ArgumentNullException(nameof(onErrorAsync));\n            if (onCompletedAsync == null)\n                throw new ArgumentNullException(nameof(onCompletedAsync));\n\n            return new UnsafeAsyncObserver<T>(onNextAsync, onErrorAsync, onCompletedAsync);\n        }\n    }\n}\n","sourceCodeStart":24,"sourceCodeEnd":48,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/AsyncObserver.cs#L24-L48","documentation":"ArgumentNullException from CreateUnsafe for onCompletedAsync being null; the message exposes 'Value cannot be null. (Parameter onCompletedAsync)'. The completion handler is mandatory in the Unsafe overload, which forwards delegates straight to UnsafeAsyncObserver<T>. The throw happens synchronously, before any observer callbacks can run.","triggerScenarios":"Calling CreateUnsafe<T>(onNext, onError, null) with a null completion delegate, e.g. a () => default handler stored in a field that was never initialized.","commonSituations":"Internal operators building observers from nullable handler fields; hand-written operators or tests omitting the completion handler; refactoring that dropped the () => default argument.","solutions":["Pass a non-null onCompletedAsync, e.g. () => default for no-op completion.","Validate all three delegates before calling CreateUnsafe.","Use the safe Create(onNextAsync) overload when custom completion/error handling is unnecessary."],"exampleFix":"// before\nAsyncObserver.CreateUnsafe<int>(onNext, onError, null);\n// after\nAsyncObserver.CreateUnsafe<int>(onNext, onError, () => default);","handlingStrategy":"validation","validationCode":"if (onCompletedAsync is null) onCompletedAsync = () => default;\nvar observer = AsyncObserver.CreateUnsafe(onNextAsync, onErrorAsync, onCompletedAsync);","typeGuard":null,"tryCatchPattern":"try\n{\n    var observer = AsyncObserver.CreateUnsafe(onNextAsync, onErrorAsync, onCompletedAsync);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"onCompletedAsync\")\n{\n    var observer = AsyncObserver.CreateUnsafe(onNextAsync, onErrorAsync, () => default);\n}","preventionTips":["Use () => default for no-op completion in unsafe observer construction.","Never leave completion-handler fields uninitialized; default them at declaration.","Validate the full delegate triple in a shared helper before any Create/CreateUnsafe call.","Cover internal operators with tests that pass each handler as null to verify fail-fast behavior."],"tags":["csharp","null-check","observer","internal-api"],"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"}