{"record":{"id":"81c8f211a07c5867","repo":"PrismLibrary/Prism","slug":"value-cannot-be-null-parameter-onnext","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'onNext')","messagePattern":"Value cannot be null\\. \\(Parameter 'onNext'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia/Prism.Avalonia/Extensions/ObservableExtensions.cs","lineNumber":26,"sourceCode":"    {\n        /// <summary>\n        /// Subscribes an element handler to an observable sequence.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Observable sequence to subscribe to.</param>\n        /// <param name=\"onNext\">Action to invoke for each element in the observable sequence.</param>\n        /// <returns><see cref=\"IDisposable\"/> object used to unsubscribe from the observable sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"onNext\"/> is <c>null</c>.</exception>\n        public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (onNext == null)\n            {\n                throw new ArgumentNullException(nameof(onNext));\n            }\n\n            //\n            // [OK] Use of unsafe Subscribe: non-pretentious constructor for an observer; this overload is not to be used internally.\n            //\n            return source.Subscribe/*Unsafe*/(new AnonymousObserver<T>(onNext, Stubs.Throw, Stubs.Nop));\n        }\n    }\n}\n","sourceCodeStart":8,"sourceCodeEnd":36,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Avalonia/Prism.Avalonia/Extensions/ObservableExtensions.cs#L8-L36","documentation":"Prism's ObservableExtensions.Subscribe extension validates the onNext callback and throws ArgumentNullException(nameof(onNext)) when the Action<T> delegate passed is null. Subscribing without a handler action is not allowed.","triggerScenarios":"Passing a null Action<T> to source.Subscribe(onNext) — e.g. a method reference that is null, a conditionally assigned handler field, or reflection-built delegate that failed to resolve.","commonSituations":"Handler assigned from configuration or DI that wasn't set; passing a variable that's null on some code path; copy-pasting Subscribe overloads and accidentally dropping the lambda.","solutions":["Pass a valid Action<T> callback to Subscribe, or use an empty lambda _ => { } if no action is needed.","Guard with onNext != null before calling Subscribe if the handler comes from external configuration.","Verify the delegate field/property holding the handler is assigned before subscription."],"exampleFix":"// before\nstream.Subscribe(_handler); // _handler is null\n// after\nstream.Subscribe(value => Handle(value));","handlingStrategy":"validation","validationCode":"if (onNext is null) throw new InvalidOperationException(\"Subscribe requires an onNext handler\");\nsource.Subscribe(onNext);","typeGuard":null,"tryCatchPattern":"try { stream.Subscribe(handler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"onNext\") { /* handler not configured */ }","preventionTips":["Never store handlers in fields that may be null at subscription time","Use a no-op lambda (_ => { }) when no action is required","Resolve handler delegates before wiring subscriptions"],"tags":["null-reference","observable","arguments","callback"],"backgroundTag":"null-argument","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}