{"record":{"id":"550bed53b4774616","repo":"dotnet/reactive","slug":"subject","errorCode":null,"errorMessage":"subject","messagePattern":"subject","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs","lineNumber":34,"sourceCode":"        /// 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>\n        /// <param name=\"source\">Source sequence which will be multicasted in the specified selector function.</param>\n        /// <param name=\"subjectSelector\">Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function.</param>\n        /// <param name=\"selector\">Selector function which can use the multicasted source sequence subject to the policies enforced by the created subject.</param>\n        /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"subjectSelector\"/> or <paramref name=\"selector\"/> is null.</exception>","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs#L16-L52","documentation":"The two-parameter Multicast(source, subject) overload throws ArgumentNullException with param name \"subject\" when the ISubject<TSource, TResult> is null. The subject is the multicast hub that receives the source's notifications and republishes them; without it the operator cannot work, so the library validates it immediately. This is the second guard in the same method after the source check.","triggerScenarios":"Calling source.Multicast(subject) where the subject argument is null — e.g. Subject.Create(observer, observable) built from null parts, a lazily-created subject field, or passing a custom ISubject implementation that a factory returned as null.","commonSituations":"Building custom hot-stream plumbing where a subject is created conditionally; DI containers that fail to resolve ISubject and inject null; typos assigning the subject after the Multicast call.","solutions":["Create the subject before calling Multicast (e.g. new Subject<T>() or AsyncSubject<T>() as appropriate).","If you do not need a custom subject, use Publish (Multicast with a Subject) instead.","Guard the subject creation so it can never be null at the call site."],"exampleFix":"// before\nvar connectable = source.Multicast(mySubject); // mySubject is null\n// after\nvar connectable = source.Multicast(new Subject<int>());","handlingStrategy":"validation","validationCode":"if (subject is null) throw new ArgumentNullException(nameof(subject));\nvar connectable = source.Multicast(subject);","typeGuard":"static bool HasSubject<TSource, TResult>(ISubject<TSource, TResult>? s) => s is not null;","tryCatchPattern":"try { connectable = source.Multicast(subject); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"subject\") { connectable = source.Multicast(new Subject<TSource>()); }","preventionTips":["Create subjects inline at the Multicast call rather than via nullable fields.","Prefer Publish() over manual Multicast unless a custom ISubject is genuinely needed.","Initialize subject fields eagerly in constructors."],"tags":["null-reference","argument-validation","rx","subject","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"}