{"record":{"id":"9b9e8c72a55be681","repo":"dotnet/reactive","slug":"subjectselector","errorCode":null,"errorMessage":"subjectSelector","messagePattern":"subjectSelector","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs","lineNumber":62,"sourceCode":"        /// </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>\n        public static IObservable<TResult> Multicast<TSource, TIntermediate, TResult>(this IObservable<TSource> source, Func<ISubject<TSource, TIntermediate>> subjectSelector, Func<IObservable<TIntermediate>, IObservable<TResult>> selector)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (subjectSelector == null)\n            {\n                throw new ArgumentNullException(nameof(subjectSelector));\n            }\n\n            if (selector == null)\n            {\n                throw new ArgumentNullException(nameof(selector));\n            }\n\n            return s_impl.Multicast(source, subjectSelector, selector);\n        }\n\n        #endregion\n\n        #region + Publish +\n\n        /// <summary>\n        /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence.\n        /// This operator is a specialization of Multicast using a regular <see cref=\"Subject{T}\"/>.\n        /// </summary>","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs#L44-L80","documentation":"The three-parameter Multicast overload throws ArgumentNullException with param name \"subjectSelector\" when the Func<ISubject<TSource, TIntermediate>> delegate is null. The subjectSelector is invoked once per connection to create the hub subject; without it the operator cannot build the multicast pipeline, so it is validated at call time.","triggerScenarios":"Passing null as the subject factory: source.Multicast(null, selector), or a variable holding a subject-creating lambda that was never assigned / resolved as null from configuration or DI.","commonSituations":"Abstracting subject creation behind a delegate (e.g. for testing) where the delegate defaults to null; conditional lambda assignment forgotten on some code path.","solutions":["Pass a non-null factory such as () => new Subject<TIntermediate>() (or AsyncSubject/BehaviorSubject as needed).","If no custom subject is needed, use the simpler Publish/Select overload.","Initialize the delegate field at declaration to avoid null in unassigned paths."],"exampleFix":"// before\nvar result = source.Multicast(subjectFactory, xs => xs.Count()); // subjectFactory is null\n// after\nvar result = source.Multicast(() => new Subject<int>(), xs => xs.Count());","handlingStrategy":"validation","validationCode":"if (subjectSelector is null) throw new ArgumentNullException(nameof(subjectSelector));\nvar result = source.Multicast(subjectSelector, selector);","typeGuard":"static bool HasSubjectFactory<TSource, TInter>(Func<ISubject<TSource, TInter>>? f) => f is not null;","tryCatchPattern":"try { result = source.Multicast(subjectSelector, selector); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"subjectSelector\") { result = source.Multicast(() => new Subject<TSource>(), selector); }","preventionTips":["Default subject factories to () => new Subject<T>() at field declaration.","Avoid optional lambda parameters in pipeline helpers; provide overloads instead.","Resolve delegates from DI with explicit null checks at startup, not at call time."],"tags":["null-reference","argument-validation","rx","delegate","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"}