{"record":{"id":"a8198cddc10df161","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-first-withlatestfrom","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/WithLatestFrom.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.Threading;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<(TFirst first, TSecond second)> WithLatestFrom<TFirst, TSecond>(this IAsyncObservable<TFirst> first, IAsyncObservable<TSecond> 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 CreateAsyncObservable<(TFirst first, TSecond second)>.From(\n                first,\n                second,\n                static async (first, second, observer) =>\n                {\n                    var (firstObserver, secondObserver) = AsyncObserver.WithLatestFrom(observer);\n\n                    // REVIEW: Consider concurrent subscriptions.\n\n                    var firstSubscription = await first.SubscribeSafeAsync(firstObserver).ConfigureAwait(false);\n                    var secondSubscription = await second.SubscribeSafeAsync(secondObserver).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(firstSubscription, secondSubscription);\n                });\n        }","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/WithLatestFrom.cs#L1-L34","documentation":"WithLatestFrom combines a source observable (first) with the latest value from another observable (second) as they arrive. The extension method validates its receiver/argument and throws ArgumentNullException with parameter name 'first' when the first (source) IAsyncObservable<TFirst> is null, failing fast before any subscription machinery is created.","triggerScenarios":"Invoking first.WithLatestFrom(second) where the receiver `first` is null, e.g. chaining off a pipeline variable that was never assigned or a factory method that returned null.","commonSituations":"Chained pipeline construction where an earlier operator returned null instead of an observable; configuration-driven pipelines where the primary source was not wired; unit tests building the chain with a null placeholder.","solutions":["Ensure the source observable assigned to `first` is created (e.g. via AsyncObservable.CreateAsyncObservable...) before chaining.","Check whether an earlier operator in the chain can return null and fix it to throw or return a valid observable.","Add a null check at pipeline construction time with a descriptive message.","If the source is optional by design, substitute an empty observable instead of null."],"exampleFix":"// before\nIAsyncObservable<int> first = GetMaybeNullSource();\nvar result = first.WithLatestFrom(second);\n// after\nvar result = (first ?? AsyncObservable.Empty<int>()).WithLatestFrom(second);","handlingStrategy":"validation","validationCode":"if (first is null) throw new ArgumentNullException(nameof(first));\nvar result = first.WithLatestFrom(second);","typeGuard":"bool IsSourceValid<T>(IAsyncObservable<T> o) => o is not null;","tryCatchPattern":"try\n{\n    var result = first.WithLatestFrom(second);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"first\")\n{\n    // fall back to an empty source pipeline\n    var result = AsyncObservable.Empty<TFirst>().WithLatestFrom(second);\n}","preventionTips":["Check that every operator earlier in the chain returns a non-null observable.","Initialize pipeline source variables at construction, not lazily at use.","Enable nullable reference types so null receivers are compile-time errors.","Substitute AsyncObservable.Empty/Never for legitimately absent sources."],"tags":["argument-null","async-rx","withlatestfrom-operator","fail-fast"],"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"}