{"record":{"id":"7079ef9a70791ada","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-multicast","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Multicast.cs","lineNumber":16,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Reactive.Disposables;\nusing System.Reactive.Subjects;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IConnectableAsyncObservable<TResult> Multicast<TSource, TResult>(this IAsyncObservable<TSource> source, IAsyncSubject<TSource, TResult> subject)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (subject == null)\n                throw new ArgumentNullException(nameof(subject));\n\n            return new ConnectableAsyncObservable<TSource, TResult>(source, subject);\n        }\n\n        public static IAsyncObservable<TSource> Multicast<TSource>(this IAsyncObservable<TSource> source, Func<IAsyncSubject<TSource>> subjectFactory)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (subjectFactory == null)\n                throw new ArgumentNullException(nameof(subjectFactory));\n\n            return Multicast(source, () => new ValueTask<IAsyncSubject<TSource, TSource>>(subjectFactory()), x => new ValueTask<IAsyncObservable<TSource>>(x));\n        }\n\n        public static IAsyncObservable<TSource> Multicast<TSource>(this IAsyncObservable<TSource> source, Func<ValueTask<IAsyncSubject<TSource>>> subjectFactory)\n        {","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Multicast.cs#L1-L34","documentation":"Multicast connects an IAsyncObservable to an IAsyncSubject to produce an IConnectableAsyncObservable. A null source observable leaves the connectable with nothing to subscribe to, so the extension method throws ArgumentNullException eagerly.","triggerScenarios":"Calling source.Multicast(subject) where the IAsyncObservable<TSource> is null; calling Publish/PublishLast/Replay (which delegate to Multicast) on a null source.","commonSituations":"Chaining off a factory method that returned null; conditional observable construction where one branch yields null; forgetting to assign the result of an async observable builder.","solutions":["Ensure the source observable is created before calling Multicast","Check the code path producing the source for a null return","Guard with a fallback empty observable if null sources are expected"],"exampleFix":"// before\nIAsyncObservable<int> src = GetSource(); // may return null\nsrc.Multicast(new AsyncSubject<int>());\n// after\nvar src = GetSource() ?? AsyncObservable.Empty<int>();\nsrc.Multicast(new AsyncSubject<int>());","handlingStrategy":"validation","validationCode":"if (source == null) throw new ArgumentNullException(nameof(source));","typeGuard":"bool IsValidSource<TSource>(IAsyncObservable<TSource> s) => s is not null;","tryCatchPattern":"try { var conn = source.Multicast(subject); } catch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* build a real source */ }","preventionTips":["Never let observable builders return null; return AsyncObservable.Empty<T>() instead","Check upstream operators for code paths yielding null","Use nullable reference types to catch null sources at compile time"],"tags":["asyncrx","argumentnull","multicast","observable"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}