{"record":{"id":"39bc3bf1bdc4f5fb","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-the-range-of-valid-values-39bc3b","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'bufferSize')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'bufferSize'\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs","lineNumber":38,"sourceCode":"            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));\n            if (bufferSize < 0)\n                throw new ArgumentOutOfRangeException(nameof(bufferSize));\n\n            return Multicast(source, new SequentialReplayAsyncSubject<TSource>(bufferSize));\n        }\n\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source, int bufferSize, IAsyncScheduler scheduler)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (bufferSize < 0)\n                throw new ArgumentOutOfRangeException(nameof(bufferSize));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Multicast(source, new SequentialReplayAsyncSubject<TSource>(bufferSize, scheduler));\n        }\n\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source, TimeSpan window)\n        {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs#L20-L56","documentation":"Replay(source, bufferSize) throws ArgumentOutOfRangeException('bufferSize') when bufferSize is negative. The replay buffer size must be >= 0; a negative value cannot describe a valid number of notifications to retain.","triggerScenarios":"Calling source.Replay(bufferSize) with bufferSize < 0, e.g. -1 used as a sentinel for 'unbounded', or a computed size that underflowed.","commonSituations":"Porting from APIs where -1 means 'infinite buffer'; config values that are negative; integer arithmetic producing a negative count (e.g. size - extra when extra > size).","solutions":["Pass a non-negative bufferSize (0 replays nothing).","If unbounded replay is intended, use the parameterless source.Replay() overload which keeps all notifications.","Clamp the value: Math.Max(0, requestedSize)."],"exampleFix":"// before\nvar size = config.BufferSize ?? -1; // -1 meant 'unbounded'\nvar replay = source.Replay(size);\n// after\nvar replay = config.BufferSize.HasValue ? source.Replay(Math.Max(0, config.BufferSize.Value)) : source.Replay();","handlingStrategy":"validation","validationCode":"if (bufferSize < 0)\n    throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, \"Buffer size must be non-negative.\");\nvar replay = source.Replay(bufferSize);","typeGuard":"static bool IsValidBufferSize(int bufferSize) => bufferSize >= 0;","tryCatchPattern":"try\n{\n    var replay = source.Replay(bufferSize);\n}\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"bufferSize\")\n{\n    var replay = source.Replay(); // fall back to unbounded\n}","preventionTips":["Don't use -1 to mean 'unbounded' with this API; call the parameterless overload instead.","Clamp configured sizes with Math.Max(0, value).","Test boundary values (0, 1, -1) when wiring buffer sizes from config."],"tags":["argument-out-of-range","rx","buffer","argument-validation"],"backgroundTag":"argument-out-of-range","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"}