{"record":{"id":"dfe6f8af5480c90a","repo":"dotnet/reactive","slug":"source-observable-binding","errorCode":null,"errorMessage":"source","messagePattern":"source","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs","lineNumber":29,"sourceCode":"    {\n        #region + Multicast +\n\n        /// <summary>\n        /// Multicasts the source sequence notifications through the specified subject to the resulting connectable observable. Upon connection of the\n        /// connectable observable, the subject is subscribed to the source exactly one, and messages are forwarded to the observers registered with\n        /// the connectable observable. For specializations with fixed subject types, see Publish, PublishLast, and Replay.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence.</typeparam>\n        /// <param name=\"source\">Source sequence whose elements will be pushed into the specified subject.</param>\n        /// <param name=\"subject\">Subject to push source elements into.</param>\n        /// <returns>A connectable observable sequence that upon connection causes the source sequence to push results into the specified subject.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"subject\"/> is null.</exception>\n        public static IConnectableObservable<TResult> Multicast<TSource, TResult>(this IObservable<TSource> source, ISubject<TSource, TResult> subject)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (subject == null)\n            {\n                throw new ArgumentNullException(nameof(subject));\n            }\n\n            return s_impl.Multicast(source, subject);\n        }\n\n        /// <summary>\n        /// Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each\n        /// subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's\n        /// invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TIntermediate\">The type of the elements produced by the intermediate subject.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence.</typeparam>","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs#L11-L47","documentation":"The two-parameter Multicast(source, subject) overload throws ArgumentNullException with param name \"source\" when the input IObservable<TSource> is null. Rx.NET validates every public operator argument up front so failures happen deterministically at call time, not at Subscribe/Connect time. Multicasting requires a real source sequence to push notifications into the subject.","triggerScenarios":"Calling source.Multicast(subject) where the IObservable<TSource> argument is null — e.g. the result of a repository/service method that returned null instead of an observable, or a field that was never assigned.","commonSituations":"Service layers that return null observables on error paths; optional dependency injection where the observable was not registered; refactoring that removed a Publish/FromEvent chain but left the variable in place.","solutions":["Provide a non-null source observable; verify the factory/method producing it never returns null.","Substitute Observable.Empty<TSource>() when there is genuinely no source.","Add a null check or ?? Observable.Empty<TSource>() fallback before calling Multicast."],"exampleFix":"// before\nvar connectable = maybeSource.Multicast(subject);\n// after\nvar connectable = (maybeSource ?? Observable.Empty<int>()).Multicast(subject);","handlingStrategy":"validation","validationCode":"if (source is null || subject is null) throw new ArgumentException(\"source and subject must be non-null\");\nvar connectable = source.Multicast(subject);","typeGuard":"static bool CanMulticast<TSource, TResult>(IObservable<TSource>? s, ISubject<TSource, TResult>? sub) => s is not null && sub is not null;","tryCatchPattern":"try { connectable = source.Multicast(subject); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { connectable = Observable.Empty<TResult>().Multicast(subject); }","preventionTips":["Centralize observable creation so null can never leak into operator chains.","Use '?? Observable.Empty<T>()' defaults when wiring optional streams.","Cover null-source paths in unit tests."],"tags":["null-reference","argument-validation","rx","multicast"],"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"}