{"record":{"id":"c86885d94cdf5ef9","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-observer-repeatwhen","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'observer')","messagePattern":"Value cannot be null\\. \\(Parameter 'observer'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable/RepeatWhen.cs","lineNumber":26,"sourceCode":"\nnamespace System.Reactive.Linq.ObservableImpl\n{\n    internal sealed class RepeatWhen<T, U> : IObservable<T>\n    {\n        private readonly IObservable<T> _source;\n        private readonly Func<IObservable<object>, IObservable<U>> _handler;\n\n        internal RepeatWhen(IObservable<T> source, Func<IObservable<object>, IObservable<U>> handler)\n        {\n            _source = source;\n            _handler = handler;\n        }\n\n        public IDisposable Subscribe(IObserver<T> observer)\n        {\n            if (observer == null)\n            {\n                throw new ArgumentNullException(nameof(observer));\n            }\n\n            var completeSignals = new Subject<object>();\n\n            IObservable<U> redo;\n\n            try\n            {\n                redo = _handler(completeSignals);\n                \n                if (redo == null)\n                {\n#pragma warning disable CA2201 // (Do not raise reserved exception types.) Backwards compatibility prevents us from complying.\n                    throw new NullReferenceException(\"The handler returned a null IObservable\");\n#pragma warning restore CA2201\n                }\n            }\n            catch (Exception ex)","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable/RepeatWhen.cs#L8-L44","documentation":"RepeatWhen wraps the source with a handler that receives completion signals; its Subscribe first validates the observer and throws ArgumentNullException(\"observer\") when null. The library cannot route OnNext/OnError/OnCompleted without a valid observer.","triggerScenarios":"Calling source.RepeatWhen(handler).Subscribe(null), or a null observer reaching Never-style argument validation inside RepeatWhenObservable.Subscribe.","commonSituations":"Observers obtained from a factory that returned null; uninitialized fields in custom subscription wrappers; refactored code dropping observer creation.","solutions":["Ensure a valid IObserver<T> is constructed before calling Subscribe.","Use the Action-based Subscribe overloads or Observer.Create<T> to build the observer.","Null-check the observer before subscribing."],"exampleFix":"// before\nsource.RepeatWhen(h => h).Subscribe(null);\n// after\nsource.RepeatWhen(h => h).Subscribe(Observer.Create<T>(onNext, onError, onCompleted));","handlingStrategy":"validation","validationCode":"// C#\nif (observer is null) throw new ArgumentNullException(nameof(observer));\nvar sub = source.RepeatWhen(c => c).Subscribe(observer);","typeGuard":"// C#\nstatic bool IsValidObserver<T>(IObserver<T> o) => o is not null;","tryCatchPattern":"try { source.RepeatWhen(c => c).Subscribe(observer); }\ncatch (ArgumentNullException ex) { Log(ex); }","preventionTips":["Resolve observers via DI factories that never return null.","Initialize observer fields eagerly or make them non-nullable.","Prefer Subscribe(onNext, onError, onCompleted) overloads."],"tags":["null-argument","repeatwhen","subscribe","argumentnull"],"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"}