{"record":{"id":"e5a9d24e64ec6853","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-oncompleted-observer","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'onCompleted')","messagePattern":"Value cannot be null\\. \\(Parameter 'onCompleted'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Observer.Extensions.cs","lineNumber":111,"sourceCode":"\n        /// <summary>\n        /// Creates an observer from the specified OnNext and OnCompleted actions.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of the elements received by the observer.</typeparam>\n        /// <param name=\"onNext\">Observer's OnNext action implementation.</param>\n        /// <param name=\"onCompleted\">Observer's OnCompleted action implementation.</param>\n        /// <returns>The observer object implemented using the given actions.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"onNext\"/> or <paramref name=\"onCompleted\"/> is null.</exception>\n        public static IObserver<T> Create<T>(Action<T> onNext, Action onCompleted)\n        {\n            if (onNext == null)\n            {\n                throw new ArgumentNullException(nameof(onNext));\n            }\n\n            if (onCompleted == null)\n            {\n                throw new ArgumentNullException(nameof(onCompleted));\n            }\n\n            return new AnonymousObserver<T>(onNext, onCompleted);\n        }\n\n        /// <summary>\n        /// Creates an observer from the specified OnNext, OnError, and OnCompleted actions.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of the elements received by the observer.</typeparam>\n        /// <param name=\"onNext\">Observer's OnNext action implementation.</param>\n        /// <param name=\"onError\">Observer's OnError action implementation.</param>\n        /// <param name=\"onCompleted\">Observer's OnCompleted action implementation.</param>\n        /// <returns>The observer object implemented using the given actions.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"onNext\"/> or <paramref name=\"onError\"/> or <paramref name=\"onCompleted\"/> is null.</exception>\n        public static IObserver<T> Create<T>(Action<T> onNext, Action<Exception> onError, Action onCompleted)\n        {\n            if (onNext == null)\n            {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Observer.Extensions.cs#L93-L129","documentation":"Observer.Create<T>(onNext, onCompleted) throws ArgumentNullException when the onCompleted delegate is null. AnonymousObserver stores both delegates and invokes onCompleted when the sequence terminates, so a null would surface as an NRE inside the library; the public factory rejects it up front.","triggerScenarios":"Calling Observer.Create<T>(onNext, null) — a null Action for the onCompleted parameter. Checked at Observer.Extensions.cs:111 after the onNext validation.","commonSituations":"Omitting the completion handler because the sequence is treated as infinite; forgetting to wire the completion callback when generating delegates dynamically; copy-pasting the single-delegate Create overload's signature incorrectly.","solutions":["Supply an onCompleted delegate, e.g. () => { }, if completion handling is not needed.","Pass null-safe wrappers built from possibly-null handlers before calling Create.","Prefer Observer.Create<T>(onNext) (single-argument overload) when only onNext matters."],"exampleFix":"// before\nvar obs = Observer.Create<int>(x => Handle(x), null);\n// after\nvar obs = Observer.Create<int>(x => Handle(x), () => { });","handlingStrategy":"validation","validationCode":"if (onCompleted == null) throw new ArgumentNullException(nameof(onCompleted));\nvar obs = Observer.Create<int>(onNext, onCompleted);","typeGuard":"static bool HasOnCompleted(Action onCompleted) => onCompleted is not null;","tryCatchPattern":"try { var obs = Observer.Create<int>(onNext, onCompleted); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"onCompleted\") { /* use single-arg overload */ }","preventionTips":["Use () => { } when completion handling is not needed.","Remember System.Reaction factories do not apply default values for delegates.","Centralize observer creation in a helper that null-coalesces all handlers."],"tags":["dotnet","reactive-extensions","argument-null","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"}