{"record":{"id":"7bec09515f7c97c5","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-replay","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/Replay.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.Reactive.Concurrency;\nusing System.Reactive.Subjects;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    // REVIEW: Expose Replay using ConcurrentAsyncAsyncSubject<T> underneath.\n\n    public partial class AsyncObservable\n    {\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return Multicast(source, new SequentialReplayAsyncSubject<TSource>());\n        }\n\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source, IAsyncScheduler scheduler)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Multicast(source, new SequentialReplayAsyncSubject<TSource>(scheduler));\n        }\n\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source, int bufferSize)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs#L1-L36","documentation":"The parameterless Replay() extension requires a non-null source IAsyncObservable. It validates arguments up front and throws ArgumentNullException before creating the SequentialReplayAsyncSubject / connectable wrapper. This is a programming error in the caller, not a runtime condition.","triggerScenarios":"Calling source.Replay() where source is null — typically the result of a factory/lookup that returned null, or chaining off a nullable expression.","commonSituations":"A GetObservable-style helper returning null on cache miss; conditional pipeline construction where an earlier step was skipped; refactoring that removed null-coalescing around the source.","solutions":["Ensure the source observable is created before calling Replay (check the factory method for null-returning paths).","Coalesce to an empty observable if a null source is legitimate: source ?? AsyncObservable.Empty<T>().","Throw early in your own factory if the source cannot be built, so failures surface at creation time."],"exampleFix":"// before\nvar src = cache.Get(key); // may be null\nvar replay = src.Replay();\n// after\nvar src = cache.Get(key) ?? AsyncObservable.Empty<int>();\nvar replay = src.Replay();","handlingStrategy":"validation","validationCode":"if (source == null)\n    throw new InvalidOperationException(\"Source observable must be created before calling Replay.\");\nvar replay = source.Replay();","typeGuard":"static bool IsNonNull<T>(IAsyncObservable<T> source) => source is not null;","tryCatchPattern":"try\n{\n    var replay = source.Replay();\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\")\n{\n    // log and fall back to building the source again\n}","preventionTips":["Make source factories non-null-returning (throw instead).","Use ?? AsyncObservable.Empty<T>() for optional sources.","Enable nullable reference types so null flows are caught at compile time."],"tags":["null-argument","rx","argument-validation"],"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"}