{"record":{"id":"8ac85f809e0577ea","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-second-concat","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'second')","messagePattern":"Value cannot be null\\. \\(Parameter 'second'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Concat.cs","lineNumber":20,"sourceCode":"// 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.Collections.Generic;\nusing System.Reactive.Disposables;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    // TODO: Implement tail call behavior to flatten Concat chains.\n\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TSource> Concat<TSource>(this IAsyncObservable<TSource> first, IAsyncObservable<TSource> second)\n        {\n            if (first == null)\n                throw new ArgumentNullException(nameof(first));\n            if (second == null)\n                throw new ArgumentNullException(nameof(second));\n\n            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        {","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Concat.cs#L2-L38","documentation":"AsyncObservable.Concat<TSource>(first, second) throws ArgumentNullException naming 'second' when the second observable is null. The guard fires immediately at the call site rather than when the sequence is subscribed.","triggerScenarios":"Calling Concat(first, null), typically when the second observable comes from a nullable source such as a config-selected provider, optional cache, or failed lookup.","commonSituations":"Conditional continuation logic where the 'next' observable is only sometimes produced; merging a primary stream with an optional fallback stream that resolved to null.","solutions":["Pass a non-null IAsyncObservable<TSource> as the second argument","Use AsyncObservable.Empty<TSource>() when the continuation is absent","Verify the code path that constructs 'second' and handle its null case before Concat"],"exampleFix":"// before\nvar result = main.Concat(continuation); // continuation is null\n// after\nvar result = main.Concat(continuation ?? AsyncObservable.Empty<int>());","handlingStrategy":"validation","validationCode":"if (second is null) throw new ArgumentNullException(nameof(second)); // or second ??= AsyncObservable.Empty<T>();","typeGuard":"public static bool IsNotNullSource<T>(IAsyncObservable<T>? s) => s is not null;","tryCatchPattern":"try { var result = first.Concat(second); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"second\") { /* supply a valid continuation or Empty<T>() */ }","preventionTips":["Default optional continuation sequences to Empty<T>()","Null-check observables returned from factories/caches before chaining","Enable nullable reference types so null flows are caught at compile time"],"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"}