{"record":{"id":"a74f2402869284c0","repo":"dotnet/reactive","slug":"null-asyncenumerablequery","errorCode":null,"errorMessage":"null","messagePattern":"null","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableQuery.cs","lineNumber":103,"sourceCode":"        /// <param name=\"expression\">The expression tree representing the asynchronous enumerable sequence.</param>\n        /// <returns>Asynchronous enumerable sequence represented by the specified expression tree.</returns>\n        IAsyncQueryable<TElement> IAsyncQueryProvider.CreateQuery<TElement>(Expression expression)\n        {\n            return new AsyncEnumerableQuery<TElement>(expression);\n        }\n\n        /// <summary>\n        /// Executes an expression tree representing a computation over asynchronous enumerable sequences.\n        /// </summary>\n        /// <typeparam name=\"TResult\">The type of the result of evaluating the expression tree.</typeparam>\n        /// <param name=\"expression\">The expression tree to evaluate.</param>\n        /// <param name=\"token\">Cancellation token used to cancel the evaluation.</param>\n        /// <returns>Task representing the result of evaluating the specified expression tree.</returns>\n        ValueTask<TResult> IAsyncQueryProvider.ExecuteAsync<TResult>(Expression expression, CancellationToken token)\n        {\n            if (expression == null)\n            {\n                throw new ArgumentNullException(nameof(expression));\n            }\n\n            if (!typeof(ValueTask<TResult>).IsAssignableFrom(expression.Type))\n            {\n                throw new ArgumentException(\"The specified expression is not assignable to the result type.\", nameof(expression));\n            }\n\n            return new AsyncEnumerableExecutor<TResult>(expression).ExecuteAsync(token);\n        }\n\n        /// <summary>\n        /// Gets an enumerator to enumerate the elements in the sequence.\n        /// </summary>\n        /// <param name=\"token\">Cancellation token used to cancel the enumeration.</param>\n        /// <returns>A new enumerator instance used to enumerate the elements in the sequence.</returns>\n        public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken token)\n        {\n            token.ThrowIfCancellationRequested();","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableQuery.cs#L85-L121","documentation":"IAsyncQueryProvider.ExecuteAsync<TResult> on AsyncEnumerableQuery validates the expression tree before executing it asynchronously. It throws ArgumentNullException(nameof(expression)) when the expression is null. This guards the boundary between query composition and async execution.","triggerScenarios":"Calling ExecuteAsync<TResult>(null, token) directly, or a provider/infrastructure layer passing a null expression when executing an async queryable.","commonSituations":"Custom query translation pipelines that can produce a null expression after filtering, mocking frameworks invoking the provider with missing arguments, or reflection-driven execution.","solutions":["Always pass a non-null Expression (e.g. the queryable's Expression property).","Null-check arguments in the calling layer before invoking the provider.","If translation can yield null, fall back to Expression.Constant of the source before executing."],"exampleFix":"// before\nvar result = await provider.ExecuteAsync<int>(null, token);\n// after\nExpression expr = query.Expression ?? Expression.Constant(query);\nvar result = await provider.ExecuteAsync<int>(expr, token);","handlingStrategy":"validation","validationCode":"if (expression == null) throw new InvalidOperationException(\"expression required before ExecuteAsync\");","typeGuard":"bool IsValid(Expression e) => e is not null;","tryCatchPattern":"try { var r = await provider.ExecuteAsync<T>(expr, token); } catch (ArgumentNullException ex) when (ex.ParamName == \"expression\") { r = await fallbackQuery.ExecuteAsync(token); }","preventionTips":["Pass query.Expression (never a possibly-null custom expression) to ExecuteAsync.","Null-check translation outputs before invoking the provider.","Cover the null-expression path in provider unit tests."],"tags":["null-argument","async","linq"],"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"}