{"record":{"id":"7d6ff5dcfb550cb9","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-repeatcount","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'repeatCount')","messagePattern":"Value cannot be null\\. \\(Parameter 'repeatCount'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Repeat.cs","lineNumber":31,"sourceCode":"    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TSource> Repeat<TSource>(TSource value)\n        {\n            return Create<TSource>(observer => AsyncObserver.Repeat(observer, value));\n        }\n\n        public static IAsyncObservable<TSource> Repeat<TSource>(TSource value, IAsyncScheduler scheduler)\n        {\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Create<TSource>(observer => AsyncObserver.Repeat(observer, value, scheduler));\n        }\n\n        public static IAsyncObservable<TSource> Repeat<TSource>(TSource value, int repeatCount)\n        {\n            if (repeatCount < 0)\n                throw new ArgumentNullException(nameof(repeatCount));\n\n            return Create<TSource>(observer => AsyncObserver.Repeat(observer, value, repeatCount));\n        }\n\n        public static IAsyncObservable<TSource> Repeat<TSource>(TSource value, int repeatCount, IAsyncScheduler scheduler)\n        {\n            if (repeatCount < 0)\n                throw new ArgumentNullException(nameof(repeatCount));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Create<TSource>(observer => AsyncObserver.Repeat(observer, value, repeatCount, scheduler));\n        }\n\n        public static IAsyncObservable<TSource> Repeat<TSource>(this IAsyncObservable<TSource> source)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Repeat.cs#L13-L49","documentation":"This Repeat(value, repeatCount) overload repeats a value a fixed number of times. Note the source guard checks repeatCount < 0 but throws ArgumentNullException naming 'repeatCount' — so this error fires when a negative count is passed (a likely copy-paste bug; ArgumentOutOfRangeException would be the expected type).","triggerScenarios":"Calling AsyncObservable.Repeat(value, repeatCount) with repeatCount < 0, e.g. a count computed from a negative constant, a failed parse defaulting to -1, or a subtraction that went below zero.","commonSituations":"Computing repeat counts from user input or config that yields -1 as a sentinel; off-by-one arithmetic producing negative values; passing int.Parse failures' sentinel values.","solutions":["Pass a repeatCount >= 0 (use 0 for no repetitions)","Clamp negative computed counts before the call, e.g. Math.Max(0, count)","Fix the upstream computation that produced a negative count"],"exampleFix":"// before\nvar obs = AsyncObservable.Repeat(42, count); // count may be -1\n// after\nvar obs = AsyncObservable.Repeat(42, Math.Max(0, count));","handlingStrategy":"validation","validationCode":"if (repeatCount < 0) throw new ArgumentOutOfRangeException(nameof(repeatCount), repeatCount, \"Must be >= 0\");\nvar obs = AsyncObservable.Repeat(value, repeatCount);","typeGuard":"static bool IsValidRepeatCount(int n) => n >= 0;","tryCatchPattern":"try\n{\n    var obs = AsyncObservable.Repeat(value, repeatCount);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"repeatCount\")\n{\n    var obs = AsyncObservable.Repeat(value, 0); // or clamp and retry\n}","preventionTips":["Clamp computed counts with Math.Max(0, count) before calling Repeat","Avoid -1 sentinels for repeat counts; use nullable int or explicit flags","Validate user/config-supplied counts at the boundary before building observables","Remember the library mislabels this as ArgumentNullException — catch that type for range issues"],"tags":["csharp","argument-validation","negative-value","reactive"],"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"}