{"record":{"id":"d60e79ea82b17d50","repo":"dotnet/reactive","slug":"source-qbservable","errorCode":null,"errorMessage":"source","messagePattern":"source","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Qbservable.cs","lineNumber":30,"sourceCode":"{\n    /// <summary>\n    /// Provides a set of static methods for writing queries over observable sequences, allowing translation to a target query language.\n    /// </summary>\n    public static partial class Qbservable\n    {\n        /// <summary>\n        /// Returns the input typed as an <see cref=\"IObservable{TSource}\"/>.\n        /// This operator is used to separate the part of the query that's captured as an expression tree from the part that's executed locally.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">An <see cref=\"IQbservable{TSource}\"/> sequence to convert to an <see cref=\"IObservable{TSource}\"/> sequence.</param>\n        /// <returns>The original source object, but typed as an <see cref=\"IObservable{TSource}\"/>.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        public static IObservable<TSource> AsObservable<TSource>(this IQbservable<TSource> source)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            return source;\n        }\n\n        /// <summary>\n        /// Converts an enumerable sequence to an observable sequence.\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        /// <returns>The observable sequence whose elements are pulled from the given enumerable sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> 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)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Qbservable.cs#L12-L48","documentation":"Qbservable.AsObservable(IQbservable<TSource>) throws ArgumentNullException when the source qbservable is null. AsObservable merely re-types the source as IObservable<TSource>, so it has no value to return when the input is null; the guard exists to fail fast with a clear message instead of a NullReferenceException later.","triggerScenarios":"Calling source.AsObservable() where source is a null IQbservable<TSource> reference — e.g. the result of a method that returned null, or an uninitialized field passed to the static form Qbservable.AsObservable(null).","commonSituations":"Factory methods or repository lookups returning null qbservables; null-conditional chains elsewhere that silently produced null; tests using null placeholders for observables.","solutions":["Ensure the upstream call that produced the IQbservable<TSource> never returns null; fix that producer to throw or return a non-null empty qbservable.","Check the source for null before calling AsObservable.","If the value is legitimately optional, guard with source?.AsObservable() and handle the null result explicitly."],"exampleFix":"// before\nIQbservable<int> source = GetSource(); // may return null\nvar obs = source.AsObservable();\n// after\nIQbservable<int> source = GetSource() ?? Qbservable.Empty<int>(provider);\nvar obs = source.AsObservable();","handlingStrategy":"validation","validationCode":"if (source is null) throw new InvalidOperationException(\"Cannot call AsObservable on a null qbservable.\");","typeGuard":"static bool IsNonNull<T>(IQbservable<T> q) => q is not null;","tryCatchPattern":"try { var obs = source.AsObservable(); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* handle missing source */ }","preventionTips":["Never let factory methods return null qbservables; return Empty or throw.","Use null-conditional operators deliberately and handle the null path explicitly.","Run nullable reference type analysis to catch uninitialized sources at compile time."],"tags":["csharp","null-reference","argument-validation","rx","qbservable"],"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"}