{"record":{"id":"c04ee089963208ac","repo":"dotnet/reactive","slug":"scheduler-qbservable","errorCode":null,"errorMessage":"scheduler","messagePattern":"scheduler","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Qbservable.cs","lineNumber":78,"sourceCode":"        /// <summary>\n        /// Converts an enumerable sequence to an observable sequence, using the specified scheduler to run the enumeration loop.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Enumerable sequence to convert to an observable sequence.</param>\n        /// <param name=\"scheduler\">Scheduler to run the enumeration of the input sequence on.</param>\n        /// <returns>The observable sequence whose elements are pulled from the given enumerable sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        /// <remarks>This operator requires the source's <see cref=\"IQueryProvider\"/> object (see <see cref=\"IQueryable.Provider\"/>) to implement <see cref=\"IQbservableProvider\"/>.</remarks>\n        public static IQbservable<TSource> ToQbservable<TSource>(this IQueryable<TSource> source, IScheduler scheduler)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return ((IQbservableProvider)source.Provider).CreateQuery<TSource>(\n                Expression.Call(\n                    null,\n                    new Func<IQueryable<TSource>, IScheduler, IQbservable <TSource>>(ToQbservable).Method,\n                    source.Expression,\n                    Expression.Constant(scheduler)\n                )\n            );\n        }\n\n        internal static Expression GetSourceExpression<TSource>(IObservable<TSource> source)\n        {\n            if (source is IQbservable<TSource> q)\n            {\n                return q.Expression;\n            }","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Qbservable.cs#L60-L96","documentation":"Qbservable.ToQbservable(IQueryable<TSource>, IScheduler) throws ArgumentNullException when the scheduler argument is null. The scheduler is encoded into the query expression to control when evaluation runs, so a null IScheduler cannot be represented and is rejected up front.","triggerScenarios":"Calling source.ToQbservable(null); passing a scheduler field/property that was never initialized; a scheduler factory or DI registration returning null (e.g. missing Scheduler.Default assignment).","commonSituations":"Configuration-driven scheduler selection where a config key maps to no scheduler; unit tests substituting null for Scheduler.Default/TestScheduler; refactors removing scheduler initialization.","solutions":["Pass a concrete scheduler such as Scheduler.Default, Scheduler.CurrentThread, or a TestScheduler in tests.","If the scheduler is configurable, default it: scheduler ?? Scheduler.Default (applied before the call).","Fix the factory/DI registration so the IScheduler binding never resolves to null."],"exampleFix":"// before\nvar q = query.ToQbservable(null);\n// after\nvar q = query.ToQbservable(Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (scheduler is null) throw new InvalidOperationException(\"An IScheduler is required for ToQbservable(scheduler).\");","typeGuard":null,"tryCatchPattern":"try { var q = query.ToQbservable(scheduler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"scheduler\") { /* fall back to Scheduler.Default or report config issue */ }","preventionTips":["Default configurable schedulers at resolution time (scheduler ?? Scheduler.Default).","Never pass null for scheduler parameters; use Scheduler.Default/Immediate/TestScheduler explicitly.","Test scheduler-dependent paths with a real TestScheduler so nulls surface early."],"tags":["csharp","null-reference","argument-validation","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"}