{"record":{"id":"7f0438b15ac62733","repo":"dotnet/reactive","slug":"nameof-scheduler","errorCode":null,"errorMessage":"nameof(scheduler)","messagePattern":"nameof\\(scheduler\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Empty.cs","lineNumber":20,"sourceCode":"// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Reactive.Concurrency;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TSource> Empty<TSource>()\n        {\n            return Create<TSource>(observer => AsyncObserver.Empty(observer));\n        }\n\n        public static IAsyncObservable<TSource> Empty<TSource>(IAsyncScheduler scheduler)\n        {\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Create<TSource>(observer => AsyncObserver.Empty(observer, scheduler));\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static ValueTask<IAsyncDisposable> Empty<TSource>(IAsyncObserver<TSource> observer) => Empty(observer, ImmediateAsyncScheduler.Instance);\n\n        public static ValueTask<IAsyncDisposable> Empty<TSource>(IAsyncObserver<TSource> observer, 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            {","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Empty.cs#L2-L38","documentation":"This is an ArgumentNullException thrown by AsyncObservable.Empty(IAsyncScheduler) when the scheduler argument is null. This overload exists to control where the completion signal is scheduled; without a scheduler the library cannot dispatch, so the null is rejected immediately. It is a fail-fast guard on the factory method.","triggerScenarios":"Calling AsyncObservable.Empty<TSource>(null), e.g. a scheduler resolved from DI/config that was not registered, or a variable assigned from a lookup that returned null.","commonSituations":"DI containers missing an IAsyncScheduler registration; choosing a scheduler via a config switch whose branch forgets assignment; tests where a scheduler mock was never set.","solutions":["Pass a concrete scheduler, e.g. ImmediateAsyncScheduler.Instance or the library's default scheduler","Fix the DI registration / factory returning a null scheduler","Use the parameterless AsyncObservable.Empty<TSource>() overload if no custom scheduling is needed"],"exampleFix":"// before\nvar empty = AsyncObservable.Empty<int>(GetScheduler()); // returns null\n// after\nvar sched = GetScheduler() ?? ImmediateAsyncScheduler.Instance;\nvar empty = AsyncObservable.Empty<int>(sched);","handlingStrategy":"validation","validationCode":"if (scheduler is null) throw new ArgumentNullException(nameof(scheduler));\nvar empty = AsyncObservable.Empty<int>(scheduler);","typeGuard":"bool HasScheduler(IAsyncScheduler s) => s is not null;","tryCatchPattern":"try { var empty = AsyncObservable.Empty<int>(scheduler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"scheduler\") { /* fall back to ImmediateAsyncScheduler.Instance */ }","preventionTips":["Register a default IAsyncScheduler in your DI container","Default null schedulers with ?? ImmediateAsyncScheduler.Instance","Prefer the parameterless Empty() overload when no custom scheduling is required"],"tags":["argument-null","async-rx","scheduler"],"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"}