{"record":{"id":"5b1e2f22bfac4e90","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-repeat","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/Repeat.cs","lineNumber":49,"sourceCode":"                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));\n\n            return Create(source, static (source, observer) => AsyncObserver.Repeat(observer, source));\n        }\n\n        public static IAsyncObservable<TSource> Repeat<TSource>(this IAsyncObservable<TSource> source, int repeatCount)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (repeatCount < 0)\n                throw new ArgumentNullException(nameof(repeatCount));\n\n            return CreateAsyncObservable<TSource>.From(\n                source,\n                repeatCount,\n                static (source, repeatCount, observer) => AsyncObserver.Repeat(observer, source, repeatCount));\n        }\n    }\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Repeat.cs#L31-L67","documentation":"System.Reactive.Async's Repeat operator validates its arguments eagerly before building the async observable. When the source IAsyncObservable<TSource> is null, the guard in the source-less overload's sibling (Repeat(source)) throws ArgumentNullException naming the 'source' parameter. This fail-fast behavior surfaces the bug at the call site rather than deep inside the reactive pipeline.","triggerScenarios":"Calling Repeat(source) (or any Repeat overload taking a source) with a null IAsyncObservable<TSource>, e.g. a variable that was never assigned, a factory method that returned null, or a null result of a previous operator chain.","commonSituations":"Passing the result of an optional lookup into a query pipeline; deserializing an observable configuration whose source property is missing; refactoring code so an observable field is initialized later than the query construction.","solutions":["Ensure the source observable is initialized before calling Repeat","Check the method or factory that produced the source for a code path returning null","Wrap construction in a null check or throw a descriptive exception at your own boundary","If null is legitimate, use AsyncObservable.Empty<TSource>() instead"],"exampleFix":"// before\nIAsyncObservable<int> src = maybeNull;\nvar repeated = src.Repeat();\n// after\nIAsyncObservable<int> src = maybeNull ?? AsyncObservable.Empty<int>();\nvar repeated = src.Repeat();","handlingStrategy":"validation","validationCode":"if (source is null) throw new ArgumentNullException(nameof(source));\nvar repeated = source.Repeat();","typeGuard":"bool IsValidSource<TSource>(IAsyncObservable<TSource> s) => s is not null;","tryCatchPattern":"try { var repeated = source.Repeat(); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\")\n{\n    // source was null; supply AsyncObservable.Empty<TSource>() or fix producer\n}","preventionTips":["Never let factory methods return null observables; return AsyncObservable.Empty<T>()","Initialize observable fields at declaration","Run nullable reference types (enable) to catch null flow at compile time","Validate inputs at your API boundary before composing Rx pipelines"],"tags":["argument-null","reactive","async-rx","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"}