{"record":{"id":"12508eca6f07f290","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-sources-concat","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'sources')","messagePattern":"Value cannot be null\\. \\(Parameter 'sources'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Concat.cs","lineNumber":40,"sourceCode":"            return Create(\n                first,\n                second,\n                static async (first, second, observer) =>\n                {\n                    var (sink, inner) = AsyncObserver.Concat(observer, second);\n\n                    var subscription = await first.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(subscription, inner);\n                });\n        }\n\n        public static IAsyncObservable<TSource> Concat<TSource>(params IAsyncObservable<TSource>[] sources) => Concat((IEnumerable<IAsyncObservable<TSource>>)sources);\n\n        public static IAsyncObservable<TSource> Concat<TSource>(this IEnumerable<IAsyncObservable<TSource>> sources)\n        {\n            if (sources == null)\n                throw new ArgumentNullException(nameof(sources));\n\n            return Create<TSource>(async observer =>\n            {\n                var enumerator = sources.GetEnumerator();\n\n                if (!enumerator.MoveNext())\n                {\n                    return AsyncDisposable.Nop; // REVIEW: Is Never behavior right here?\n                }\n\n                var source = enumerator.Current;\n\n                var (sink, inner) = AsyncObserver.Concat(observer, enumerator);\n\n                var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                return StableCompositeAsyncDisposable.Create(subscription, inner);\n            });","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Concat.cs#L22-L58","documentation":"AsyncObservable.Concat<TSource>(params sources) and the IEnumerable overload throw ArgumentNullException naming 'sources' when the sequence of observables itself is null. Note: the params overload also throws if you pass a single null cast explicitly; the array itself must be non-null.","triggerScenarios":"Calling Concat((IEnumerable<IAsyncObservable<TSource>>)null), or Concat(sources) where a method returning the collection returned null; also passing a null array through the params overload via an explicit cast.","commonSituations":"Dynamically built lists of sources from config or DI where the aggregation step returned null; serialization frameworks deserializing an absent collection to null.","solutions":["Pass a non-null collection of observables","Default null collections to an empty array/list: sources ?? Array.Empty<IAsyncObservable<T>>()","Fix the producer that returns null instead of an empty collection"],"exampleFix":"// before\nvar merged = AsyncObservable.Concat(sources); // sources is null\n// after\nvar merged = AsyncObservable.Concat(sources ?? Array.Empty<IAsyncObservable<int>>());","handlingStrategy":"validation","validationCode":"var safeSources = sources ?? Array.Empty<IAsyncObservable<TSource>>();","typeGuard":"public static bool HasSources<T>(IEnumerable<IAsyncObservable<T>>? s) => s is not null;","tryCatchPattern":"try { var merged = AsyncObservable.Concat(sources); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"sources\") { /* use an empty collection */ }","preventionTips":["Never return null collections from producer methods; return empty ones","Null-coalesce config/DI-provided collections before use","Avoid casting null through the params overload with explicit casts"],"tags":["argument-null","concat","async-rx"],"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"}