dotnet/reactive · error · InvalidOperationException

Could not find method with name '{0}' on type '{1}'.

Error message

Could not find method with name '{0}' on type '{1}'.

What it means

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.

Solutions

  1. 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.
  2. Explicitly specify generic type arguments or cast arguments so they match an existing AsyncEnumerable method signature.
  3. Materialize the unsupported part of the query before/after translation (e.g. use ToAsyncEnumerable() on the non-translatable piece).
  4. Check you are using the matching System.Linq.Async.Queryable / System.Linq.Async package versions and upgrade if a needed overload was added later.

Example fix

// before
var q = source.Select(x => new { x.A, x.B }).Where(a => a.A > 0); // custom overload the rewriter can't match
// after
var q = source.Select((System.Linq.Expressions.Expression<Func<Item, ItemDto>>)(x => new ItemDto { A = x.A, B = x.B }))
              .Where(dto => dto.A > 0); // standard overloads with explicit types
Defensive patterns

Strategy: try-catch

Validate before calling

// verify the operator exists with matching arg types before building the query
var mi = typeof(System.Linq.AsyncEnumerable).GetMethods()
    .FirstOrDefault(m => m.Name == "Select" && /* arg types match */ m.GetParameters().Length == 2);
if (mi == null) throw new InvalidOperationException("operator not translatable");

Type guard

static bool IsTranslatable(string name, Type[] argTypes) =>
    typeof(System.Linq.AsyncEnumerable).GetMethods()
        .Any(m => m.Name == name && m.GetParameters().Length == argTypes.Length);

Try / catch

try
{
    var result = query.ToListAsync().GetAwaiter().GetResult();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Could not find method with name"))
{
    // fall back to client-side evaluation or log translation failure
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15). Data as JSON: /api/errors/d9ea9a06944304eb. Report an issue: GitHub.

Appendix: source

Thrown at Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/AsyncEnumerableRewriter.cs:407

            }

            return elemType.MakeArrayType();
        }

        private static MethodInfo FindEnumerableMethod(string name, ReadOnlyCollection<Expression> args, params Type[]? typeArgs)
        {
            //
            // Ensure the cached lookup table for AsyncEnumerable methods is initialized.
            //
            _methods ??= typeof(AsyncEnumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).ToLookup(m => m.Name);

            //
            // Find a match based on the method name and the argument types.
            //
            var method = _methods[name].FirstOrDefault(m => ArgsMatch(m, args, typeArgs));
            if (method == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Could not find method with name '{0}' on type '{1}'.", name, typeof(Enumerable)));
            }

            //
            // Close the generic method if needed.
            //
            if (typeArgs != null)
            {
                return method.MakeGenericMethod(typeArgs);
            }

            return method;
        }

        private static MethodInfo FindMethod(Type type, string name, ReadOnlyCollection<Expression> args, Type[]? typeArgs, BindingFlags flags)
        {
            //
            // Support the enumerable methods to be defined on another type.
            //

View on GitHub (pinned to 94b5d5ab91)