{"record":{"id":"7ef9086811203491","repo":"PrismLibrary/Prism","slug":"value-cannot-be-null-parameter-source","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia/Prism.Avalonia/Extensions/ObservableExtensions.cs","lineNumber":21,"sourceCode":"using Prism.Common;\n\nnamespace Prism.Extensions\n{\n    internal static class ObservableExtensions\n    {\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":3,"sourceCodeEnd":36,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Avalonia/Prism.Avalonia/Extensions/ObservableExtensions.cs#L3-L36","documentation":"Prism's ObservableExtensions.Subscribe extension performs an explicit null check on the IObservable<T> source before subscribing and throws ArgumentNullException(nameof(source)) when it is null. This guards the extension method against being invoked on a null receiver.","triggerScenarios":"Calling someObservable.Subscribe(x => ...) where someObservable is a null IObservable<T> reference — e.g. a property/field never initialized, a factory method that returned null, or a service-injected stream not registered in the container.","commonSituations":"Subscribing to an event stream from an injected service that wasn't registered; a method like GetObservable() returning null on some code path; refactoring where the observable field was removed but the subscription remained.","solutions":["Ensure the IObservable<T> source is initialized before calling Subscribe (constructor/property initialization).","Null-check the source or use source?.Subscribe(...) if null is a valid state you want to skip.","Fix the factory/provider that returns null instead of a non-null (possibly empty) observable."],"exampleFix":"// before\n_stream.Subscribe(OnNext); // _stream may be null\n// after\n_stream ??= Observable.Empty<int>();\n_stream.Subscribe(OnNext);","handlingStrategy":"validation","validationCode":"if (source is null) throw new InvalidOperationException(\"Observable source not initialized\");\nsource.Subscribe(onNext);","typeGuard":"IObservable<T>? EnsureStream<T>(IObservable<T>? s) => s ?? Observable.Empty<T>();","tryCatchPattern":"try { _stream.Subscribe(OnNext); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* log: stream not initialized */ }","preventionTips":["Initialize observable streams in the constructor, never leave them null","Prefer a non-null empty observable over null as a 'no data' state","Validate injected services expose initialized streams"],"tags":["null-reference","observable","arguments","reactive"],"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"}