reactiveui/refit · error · InvalidOperationException

No suitable Method found...

Error message

No suitable Method found...

What it means

After filtering overloads by supplied parameter types and attempting to close generic methods, none of the candidates' parameters matched. Generic-constraint violations during closure are deliberately swallowed, so this is the catch-all for 'no overload fits'. It is an InvalidOperationException rather than ArgumentException because resolution itself failed, not the request shape.

Source

Thrown at src/Refit.Reflection/RequestBuilderImplementation.cs:411

            return CloseGenericMethodIfNeeded(possibleMethods[0], genericArgumentTypes);
        }

        foreach (var method in possibleMethods)
        {
            try
            {
                var closedMethod = CloseGenericMethodIfNeeded(method, genericArgumentTypes);
                if (ParametersMatch(closedMethod.MethodInfo.GetParameters(), parameterTypes))
                {
                    return closedMethod;
                }
            }
            catch (Exception exception) when (exception.Message.Contains("violates the constraint", StringComparison.CurrentCultureIgnoreCase))
            {
            }
        }

        throw new InvalidOperationException("No suitable Method found...");
    }

    /// <summary>Closes an open generic rest method over the supplied type arguments, caching the result.</summary>
    /// <param name="restMethodInfo">The (possibly generic) rest method.</param>
    /// <param name="genericArgumentTypes">The generic argument types, or null if not generic.</param>
    /// <returns>The closed rest method info, or the original when no generic arguments are supplied.</returns>
    [RequiresUnreferencedCode("Closing generic Refit methods requires generic method metadata to be available at runtime.")]
    [RequiresDynamicCode("Closing generic Refit methods requires runtime generic method instantiation.")]
    internal RestMethodInfoInternal CloseGenericMethodIfNeeded(
        RestMethodInfoInternal restMethodInfo,
        Type[]? genericArgumentTypes) =>
        genericArgumentTypes is { } genericArguments
            ? _interfaceGenericHttpMethods.GetOrAdd(
                new(restMethodInfo.MethodInfo, genericArguments),
                static (_, state) =>
                    new RestMethodInfoInternal(
                        state.RestMethod.Type,
                        state.RestMethod.MethodInfo.MakeGenericMethod(state.GenericArguments),

View on GitHub (pinned to b455f65ecc)

Solutions

  1. Check the generic constraints on the interface method and ensure the type argument satisfies them.
  2. Verify the parameterTypes you pass match the overload's signature exactly (order, count, types).
  3. If the inner closure threw a constraint error, test closing the generic yourself in a unit test to surface the real message.

Example fix

// before
public interface IApi {
    [Post("/items")] Task PostAsync<T>([Body] T item) where T : class;
}
await api.PostAsync(123); // int violates 'where T : class' -> swallowed -> No suitable Method found

// after
await api.PostAsync(new Item { ... }); // reference type satisfies constraint
Defensive patterns

Strategy: validation

Validate before calling

// Verify generic constraints yourself before calling.
static void AssertSatisfies<TMethod>(Type genericArg) where TMethod : class {
    var constraints = typeof(TMethod).GetGenericArguments()[0].GetGenericParameterConstraints();
    foreach (var c in constraints)
        if (!c.IsAssignableFrom(genericArg))
            throw new InvalidOperationException($"{genericArg} violates constraint {c}.");
}

Prevention

When it happens

Trigger: Calling a generic Refit method with generic argument types and parameter types that none of the overloads accept, or where the generic type arguments violate constraints (the constraint error is eaten and you get this instead).

Common situations: Passing a generic type that does not satisfy a `where T :` constraint; mismatch between supplied parameterTypes and the method's actual signature; wrong number of generic arguments.

Related errors


AI-assisted analysis of reactiveui/refit@b455f65ecc (2026-08-13). Data as JSON: /api/errors/3028244836867018. Report an issue: GitHub.