{"record":{"id":"d9ea9a06944304eb","repo":"dotnet/reactive","slug":"could-not-find-method-with-name-0-on-type-1","errorCode":null,"errorMessage":"Could not find method with name '{0}' on type '{1}'.","messagePattern":"Could not find method with name '(.+?)' on type '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableRewriter.cs","lineNumber":407,"sourceCode":"            }\n\n            return elemType.MakeArrayType();\n        }\n\n        private static MethodInfo FindEnumerableMethod(string name, ReadOnlyCollection<Expression> args, params Type[]? typeArgs)\n        {\n            //\n            // Ensure the cached lookup table for AsyncEnumerable methods is initialized.\n            //\n            _methods ??= typeof(AsyncEnumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).ToLookup(m => m.Name);\n\n            //\n            // Find a match based on the method name and the argument types.\n            //\n            var method = _methods[name].FirstOrDefault(m => ArgsMatch(m, args, typeArgs));\n            if (method == null)\n            {\n                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, \"Could not find method with name '{0}' on type '{1}'.\", name, typeof(Enumerable)));\n            }\n\n            //\n            // Close the generic method if needed.\n            //\n            if (typeArgs != null)\n            {\n                return method.MakeGenericMethod(typeArgs);\n            }\n\n            return method;\n        }\n\n        private static MethodInfo FindMethod(Type type, string name, ReadOnlyCollection<Expression> args, Type[]? typeArgs, BindingFlags flags)\n        {\n            //\n            // Support the enumerable methods to be defined on another type.\n            //","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableRewriter.cs#L389-L425","documentation":"Thrown by AsyncEnumerableRewriter.FindEnumerableMethod when rewrites a query expression into async enumerable calls. The rewriter looks up candidate methods by name in its cached table of System.Enumerable (async) methods and filters by argument type; if no candidate's signature matches the supplied args/type args, it fails with this InvalidOperationException. It means the queryable provider encountered a query pattern the async rewriter cannot translate.","triggerScenarios":"Calling an async queryable operator whose name exists in the rewriter's _methods table but whose argument types do not match any overload, e.g. passing a selector/lambda of a shape AsyncEnumerable does not define, or wrong generic type arguments, so ArgsMatch returns false for all candidates.","commonSituations":"Using a custom extension method or an unsupported overload inside an AsAsyncQueryable()/async query expression; version drift where the referenced System.Linq.Async version lacks an overload the compiler accepted; passing null or mismatched type arguments in a translated method call.","solutions":["Inspect the method name and argument types in the exception message and change the query to use an overload that System.Linq.Async actually defines.","Explicitly specify generic type arguments or cast arguments so they match an existing AsyncEnumerable method signature.","Materialize the unsupported part of the query before/after translation (e.g. use ToAsyncEnumerable() on the non-translatable piece).","Check you are using the matching System.Linq.Async.Queryable / System.Linq.Async package versions and upgrade if a needed overload was added later."],"exampleFix":"// before\nvar q = source.Select(x => new { x.A, x.B }).Where(a => a.A > 0); // custom overload the rewriter can't match\n// after\nvar q = source.Select((System.Linq.Expressions.Expression<Func<Item, ItemDto>>)(x => new ItemDto { A = x.A, B = x.B }))\n              .Where(dto => dto.A > 0); // standard overloads with explicit types","handlingStrategy":"try-catch","validationCode":"// verify the operator exists with matching arg types before building the query\nvar mi = typeof(System.Linq.AsyncEnumerable).GetMethods()\n    .FirstOrDefault(m => m.Name == \"Select\" && /* arg types match */ m.GetParameters().Length == 2);\nif (mi == null) throw new InvalidOperationException(\"operator not translatable\");","typeGuard":"static bool IsTranslatable(string name, Type[] argTypes) =>\n    typeof(System.Linq.AsyncEnumerable).GetMethods()\n        .Any(m => m.Name == name && m.GetParameters().Length == argTypes.Length);","tryCatchPattern":"try\n{\n    var result = query.ToListAsync().GetAwaiter().GetResult();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Could not find method with name\"))\n{\n    // fall back to client-side evaluation or log translation failure\n}","preventionTips":["Use only operators documented by System.Linq.Async in async queryables.","Pin System.Linq.Async and System.Linq.Async.Queryable to matching versions.","Keep lambdas in queries as typed Expression<...> so overload matching succeeds.","Test every query shape in CI to catch translation gaps early."],"tags":["linq","expression-translation","queryable","async"],"backgroundTag":"unsupported-operation","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"}