{"record":{"id":"77919a559bc903be","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-observer-repeat","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'observer')","messagePattern":"Value cannot be null\\. \\(Parameter 'observer'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Repeat.cs","lineNumber":73,"sourceCode":"        {\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\n    public partial class AsyncObserver\n    {\n        public static ValueTask<IAsyncDisposable> Repeat<TSource>(IAsyncObserver<TSource> observer, TSource value)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            return Repeat(observer, value, TaskPoolAsyncScheduler.Default);\n        }\n\n        public static ValueTask<IAsyncDisposable> Repeat<TSource>(IAsyncObserver<TSource> observer, TSource value, IAsyncScheduler scheduler)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return scheduler.ScheduleAsync(async ct =>\n            {\n                while (!ct.IsCancellationRequested)\n                {\n                    await observer.OnNextAsync(value).RendezVous(scheduler, ct);\n                }\n            });","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Repeat.cs#L55-L91","documentation":"The AsyncObserver.Repeat(observer, value) factory (used to build async observers) requires a non-null IAsyncObserver<TSource> and throws ArgumentNullException with Parameter 'observer' when violated. Custom operator authors calling these low-level AsyncObserver factories must supply the downstream observer they were handed.","triggerScenarios":"Implementing a custom async operator and calling AsyncObserver.Repeat(observer, value) or AsyncObserver.Repeat(observer, value, scheduler) with a null observer — typically because the custom SubscribeAsync implementation did not receive or forward a valid observer.","commonSituations":"Writing custom Rx operators; wiring observers through DI where the dependency was not registered; calling the observer factory outside a Subscribe pipeline where no observer exists.","solutions":["Pass the observer instance supplied to your SubscribeAsync/Subscribe implementation","Check DI/factory wiring that should have provided the observer","Ensure your custom operator forwards the observer parameter rather than dropping it","If constructing standalone, create an observer (e.g. via AsyncObserver.Create) instead of passing null"],"exampleFix":"// before\npublic ValueTask<IAsyncDisposable> SubscribeAsync(IAsyncObserver<int> observer)\n    => AsyncObserver.Repeat(null, 42);\n// after\npublic ValueTask<IAsyncDisposable> SubscribeAsync(IAsyncObserver<int> observer)\n    => AsyncObserver.Repeat(observer, 42);","handlingStrategy":"validation","validationCode":"if (observer is null) throw new ArgumentNullException(nameof(observer));\nvar disp = await AsyncObserver.Repeat(observer, value);","typeGuard":"bool IsValidObserver<TSource>(IAsyncObserver<TSource> o) => o is not null;","tryCatchPattern":"try { var disp = await AsyncObserver.Repeat(observer, value); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\")\n{\n    // forward the real observer from Subscribe instead of null\n}","preventionTips":["In custom operators, always forward the observer argument from Subscribe/SubscribeAsync","Never construct observers as standalone calls with null; use AsyncObserver.Create","Check DI registration for observer dependencies","Keep operator plumbing symmetric: pass through every parameter you receive"],"tags":["argument-null","reactive","async-rx","custom-operator"],"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"}