{"record":{"id":"db2af8d265ca08b3","repo":"dotnet/reactive","slug":"nameof-scheduler-observable-creation","errorCode":null,"errorMessage":"nameof(scheduler)","messagePattern":"nameof\\(scheduler\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs","lineNumber":316,"sourceCode":"#pragma warning disable IDE0060 // (Remove unused parameter.) Required for type inference\n        public static IObservable<TResult> Empty<TResult>(TResult witness)\n#pragma warning restore IDE0060\n        {\n            return s_impl.Empty<TResult>(); // Pure inference - no specialized target method.\n        }\n\n        /// <summary>\n        /// Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type used for the <see cref=\"IObservable{T}\"/> type parameter of the resulting sequence.</typeparam>\n        /// <param name=\"scheduler\">Scheduler to send the termination call on.</param>\n        /// <returns>An observable sequence with no elements.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"scheduler\"/> is null.</exception>\n        public static IObservable<TResult> Empty<TResult>(IScheduler scheduler)\n        {\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return s_impl.Empty<TResult>(scheduler);\n        }\n\n        /// <summary>\n        /// Returns an empty observable sequence, using the specified scheduler to send out the single OnCompleted message.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type used for the <see cref=\"IObservable{T}\"/> type parameter of the resulting sequence.</typeparam>\n        /// <param name=\"scheduler\">Scheduler to send the termination call on.</param>\n        /// <param name=\"witness\">Object solely used to infer the type of the <typeparamref name=\"TResult\"/> type parameter. This parameter is typically used when creating a sequence of anonymously typed elements.</param>\n        /// <returns>An observable sequence with no elements.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"scheduler\"/> is null.</exception>\n#pragma warning disable IDE0060 // (Remove unused parameter.) Required for type inference\n        public static IObservable<TResult> Empty<TResult>(IScheduler scheduler, TResult witness)\n#pragma warning restore IDE0060\n        {\n            if (scheduler == null)","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs#L298-L334","documentation":"Observable.Empty<TResult>(IScheduler) emits the completion notification on the supplied scheduler, which must be non-null. Rx throws ArgumentNullException to ensure the scheduling behavior is explicit; without a scheduler the parameterless overload should be used instead.","triggerScenarios":"Calling Observable.Empty<TResult>(scheduler) with a null IScheduler, typically when the scheduler comes from a nullable parameter, property, or service that was not provided.","commonSituations":"Test code where Scheduler defaults were not injected, DI misconfiguration returning null for IScheduler, or a wrapper API forwarding a null scheduler.","solutions":["Pass a concrete scheduler such as Scheduler.Default, Scheduler.Immediate, or Scheduler.CurrentThread.","Use the parameterless Observable.Empty<TResult>() when no custom scheduling is needed.","Null-check the scheduler before calling and substitute Scheduler.Default when null."],"exampleFix":"// before\nvar obs = Observable.Empty<int>(scheduler); // scheduler null\n// after\nvar obs = Observable.Empty<int>(scheduler ?? Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (scheduler is null) throw new ArgumentNullException(nameof(scheduler));\nvar obs = Observable.Empty<int>(scheduler);","typeGuard":"bool IsValid(IScheduler s) => s is not null;","tryCatchPattern":"try { var obs = Observable.Empty<int>(scheduler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"scheduler\") { obs = Observable.Empty<int>(); }","preventionTips":["Default null schedulers to Scheduler.Default at the entry point","Use the parameterless Observable.Empty<T>() when no custom scheduler is needed","Make IScheduler a required constructor dependency so DI fails fast"],"tags":["argumentnull","reactive-extensions","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"}