{"record":{"id":"233737f5713cf5d0","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-first-concat","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'first')","messagePattern":"Value cannot be null\\. \\(Parameter 'first'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Concat.cs","lineNumber":18,"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.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","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Concat.cs#L1-L36","documentation":"AsyncObservable.Concat<TSource>(first, second) requires both source observables to be non-null and throws ArgumentNullException naming 'first' when the first one is null. This is an eager, fail-fast guard so you never get a null-dereference deep inside the subscription pipeline later.","triggerScenarios":"Calling Concat with a null first argument, e.g. AsyncObservable.Concat(null, second), often because an expression or dictionary lookup that was supposed to produce the first observable returned null.","commonSituations":"Chaining Concat in a LINQ-style pipeline where a factory method or conditional returned null instead of an empty observable; refactors where a variable became nullable; test setups that pass null placeholders.","solutions":["Pass a non-null IAsyncObservable<TSource> as the first argument","If a value can legitimately be absent, substitute AsyncObservable.Empty<TSource>() instead of null","Check the expression producing 'first' for unintended null returns (failed lookups, unassigned fields)"],"exampleFix":"// before\nvar result = firstSource.Concat(secondSource); // firstSource is null\n// after\nvar result = (firstSource ?? AsyncObservable.Empty<int>()).Concat(secondSource);","handlingStrategy":"validation","validationCode":"if (first is null) throw new ArgumentNullException(nameof(first)); // or ensure before call: first ??= 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 == \"first\") { /* supply a valid source or Empty<T>() */ }","preventionTips":["Treat IAsyncObservable parameters as non-nullable and enable C# nullable reference types","Substitute AsyncObservable.Empty<T>() instead of null for absent sequences","Null-check inputs at pipeline boundaries before composing operators"],"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"}