{"record":{"id":"123b33df01fa0542","repo":"dotnet/reactive","slug":"source-qbservable-joins","errorCode":null,"errorMessage":"source","messagePattern":"source","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Qbservable.Joins.cs","lineNumber":60,"sourceCode":"                    GetSourceExpression(right)\n                )\n            );\n        }\n\n        /// <summary>\n        /// Matches when the observable sequence has an available element and projects the element by invoking the selector function.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence, returned by the selector function.</typeparam>\n        /// <param name=\"source\">Observable sequence to apply the selector on.</param>\n        /// <param name=\"selector\">Selector that will be invoked for elements in the source sequence.</param>\n        /// <returns>Plan that produces the projected results, to be fed (with other plans) to the When operator.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"selector\"/> is null.</exception>\n        public static QueryablePlan<TResult> Then<TSource, TResult>(this IQbservable<TSource> source, Expression<Func<TSource, TResult>> selector)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (selector == null)\n            {\n                throw new ArgumentNullException(nameof(selector));\n            }\n\n            return new QueryablePlan<TResult>(\n                Expression.Call(\n                    null,\n                    new Func<IQbservable<TSource>, Expression<Func<TSource, TResult>>, QueryablePlan<TResult>>(Then).Method,\n                    source.Expression,\n                    selector\n                )\n            );\n        }\n\n        /// <summary>","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Qbservable.Joins.cs#L42-L78","documentation":"Then(source, selector) creates a QueryablePlan from a pattern source and an expression-tree selector; both must be non-null. The method throws ArgumentNullException(\"source\") when the IQbservable<TSource> is null. The check runs before the Expression.Call for the Then operator is constructed, since a null source cannot appear in a valid queryable expression.","triggerScenarios":"Calling source.Then(selector) on a null IQbservable<TSource>, typically a pattern stage produced by a provider method that returned null.","commonSituations":"Building When/Then join plans where an earlier And/chain step yielded null instead of a queryable sequence.","solutions":["Ensure the source pattern comes from a valid IQbservableProvider chain ending in And/Then.","Substitute an empty queryable sequence if the source legitimately has no data.","Null-check the source before calling Then."],"exampleFix":"// before\nvar plan = source.Then(x => x * 2); // source == null\n// after\nvar plan = (source ?? provider.CreateQuery<int>(Observable.Empty<int>())).Then(x => x * 2);","handlingStrategy":"validation","validationCode":"if (source is null) throw new InvalidOperationException(\"Then requires a non-null IQbservable source\");\nvar plan = source.Then(selector);","typeGuard":"bool HasPatternSource<TS>(IQbservable<TS>? s) => s is not null;","tryCatchPattern":"try { var plan = source.Then(proj); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* rebuild the pattern source from the provider */ }","preventionTips":["Build Then plans only from provider-created queryables","Verify each chain step returns non-null before the next","Keep join-plan construction in one place with null assertions"],"tags":["argument-null","qbservable","plan","rx","dotnet"],"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"}