{"record":{"id":"33c0de502bcc2650","repo":"dotnet/reactive","slug":"could-not-find-a-matching-method-with-name-0-on-type-1","errorCode":null,"errorMessage":"Could not find a matching method with name '{0}' on type '{1}'.","messagePattern":"Could not find a matching 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":443,"sourceCode":"            //\n            var targetType = type.GetTypeInfo().GetCustomAttribute<LocalQueryMethodImplementationTypeAttribute>()?.TargetType ?? type;\n\n            //\n            // Get all the candidates based on name and fail if none are found.\n            //\n            var methods = targetType.GetMethods(flags).Where(m => m.Name == name).ToArray();\n            if (methods.Length == 0)\n            {\n                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, \"Could not find method with name '{0}' on type '{1}'.\", name, type));\n            }\n\n            //\n            // Find a match based on arguments and fail if no match is found.\n            //\n            var method = methods.FirstOrDefault(m => ArgsMatch(m, args, typeArgs));\n            if (method == null)\n            {\n                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, \"Could not find a matching method with name '{0}' on type '{1}'.\", name, type));\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 Type? FindGenericType(Type definition, Type? type)\n        {\n            while (type != null && type != typeof(object))\n            {\n                //","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableRewriter.cs#L425-L461","documentation":"Thrown by AsyncEnumerableRewriter.FindMethod when the target type DOES have methods with the requested name, but none of their signatures match the supplied argument types or generic type arguments (ArgsMatch fails for every candidate). Unlike the 'no such method' case, this is an overload-resolution failure during expression rewriting.","triggerScenarios":"Calling an operator with argument types that fit no overload, e.g. wrong lambda parameter type, omitted type arguments the rewriter cannot infer, or passing a Func where an Expression is expected inside an async queryable expression.","commonSituations":"Migrating LINQ-to-Objects queries to async queryables where overloads differ; implicit conversions not applied inside expression trees; using int where long (or vice versa) breaks overload matching during rewrite.","solutions":["Adjust the arguments so their types exactly match one declared overload (add explicit casts or typed lambda parameters).","Supply explicit generic type arguments to the operator call.","Convert lambdas to the exact Expression/Func form the target overload expects.","If no overload is right for translation, do that operation outside the queryable expression."],"exampleFix":"// before\nvar q = source.Select(x => (long)x.A); // matches no overload during rewrite\n// after\nvar q = source.Select((Expression<Func<Item, long>>)(x => x.A)); // exact overload signature","handlingStrategy":"validation","validationCode":"var matches = targetType.GetMethods().Where(m => m.Name == opName);\nbool anyFit = matches.Any(m => m.GetParameters().Length == argCount);\nif (!anyFit) throw new InvalidOperationException($\"no {opName} overload takes {argCount} args\");","typeGuard":"static bool OverloadExists(Type t, string name, int argCount) =>\n    t.GetMethods().Any(m => m.Name == name && m.GetParameters().Length == argCount);","tryCatchPattern":"try\n{\n    var result = query.ToListAsync().GetAwaiter().GetResult();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Could not find a matching method\"))\n{\n    // fall back to composing the query with supported overloads\n}","preventionTips":["Annotate lambda parameters with explicit types so overload matching is unambiguous.","Specify generic type arguments explicitly when inference may fail.","Match numeric literal types (int vs long, double vs decimal) to the overload signatures.","Keep translations testable by unit-testing the query composition."],"tags":["linq","overload-resolution","expression-translation","async"],"backgroundTag":"type-mismatch","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"}