{"record":{"id":"77e28d6519bf0a3f","repo":"dotnet/reactive","slug":"argumentnullexception-observable-queryable","errorCode":null,"errorMessage":"ArgumentNullException","messagePattern":"ArgumentNullException","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Queryable.cs","lineNumber":44,"sourceCode":"            {\n                s_provider ??= new ObservableQueryProvider();\n\n                return s_provider;\n            }\n        }\n\n        /// <summary>\n        /// Converts an in-memory observable sequence into an <see cref=\"IQbservable{T}\"/> sequence with an expression tree representing the source sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <returns><see cref=\"IQbservable{T}\"/> sequence representing the given observable source sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        public static IQbservable<TSource> AsQbservable<TSource>(this IObservable<TSource> source)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            return new ObservableQuery<TSource>(source);\n        }\n    }\n}\n","sourceCodeStart":26,"sourceCodeEnd":51,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Queryable.cs#L26-L51","documentation":"AsQbservable wraps an IObservable<T> into an IQbservable<T> (queryable observable for expression-based LINQ providers). Because a null source cannot be wrapped, the extension method validates `source` and throws ArgumentNullException synchronously at the call site.","triggerScenarios":"Calling source.AsQbservable() where source is null — e.g. a service property or method result that is null instead of an observable sequence.","commonSituations":"DI-injected stream properties not yet initialized; methods returning null instead of Observable.Empty; chaining off an optional sequence without null checks.","solutions":["Null-check the sequence before calling AsQbservable.","Fix the producer to return Observable.Empty<TSource>() instead of null.","Use the null-coalescing operator: (source ?? Observable.Empty<TSource>()).AsQbservable()."],"exampleFix":"// before\nvar q = source.AsQbservable();\n// after\nvar q = (source ?? Observable.Empty<int>()).AsQbservable();","handlingStrategy":"validation","validationCode":"if (source is null) throw new ArgumentNullException(nameof(source));","typeGuard":"static bool IsSource<T>(IObservable<T>? s) => s is not null;","tryCatchPattern":"try { var q = source.AsQbservable(); }\ncatch (ArgumentNullException ex) { logger.LogError(ex, \"AsQbservable requires a non-null source\"); }","preventionTips":["Enable nullable reference types so null sources are caught at compile time.","Coalesce with Observable.Empty<TSource>() when a sequence is optional.","Fix producers to never return null observables."],"tags":["csharp","rx","argument-null"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}