{"record":{"id":"3028244836867018","repo":"reactiveui/refit","slug":"no-suitable-method-found","errorCode":null,"errorMessage":"No suitable Method found...","messagePattern":"No suitable Method found\\.\\.\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Refit.Reflection/RequestBuilderImplementation.cs","lineNumber":411,"sourceCode":"            return CloseGenericMethodIfNeeded(possibleMethods[0], genericArgumentTypes);\n        }\n\n        foreach (var method in possibleMethods)\n        {\n            try\n            {\n                var closedMethod = CloseGenericMethodIfNeeded(method, genericArgumentTypes);\n                if (ParametersMatch(closedMethod.MethodInfo.GetParameters(), parameterTypes))\n                {\n                    return closedMethod;\n                }\n            }\n            catch (Exception exception) when (exception.Message.Contains(\"violates the constraint\", StringComparison.CurrentCultureIgnoreCase))\n            {\n            }\n        }\n\n        throw new InvalidOperationException(\"No suitable Method found...\");\n    }\n\n    /// <summary>Closes an open generic rest method over the supplied type arguments, caching the result.</summary>\n    /// <param name=\"restMethodInfo\">The (possibly generic) rest method.</param>\n    /// <param name=\"genericArgumentTypes\">The generic argument types, or null if not generic.</param>\n    /// <returns>The closed rest method info, or the original when no generic arguments are supplied.</returns>\n    [RequiresUnreferencedCode(\"Closing generic Refit methods requires generic method metadata to be available at runtime.\")]\n    [RequiresDynamicCode(\"Closing generic Refit methods requires runtime generic method instantiation.\")]\n    internal RestMethodInfoInternal CloseGenericMethodIfNeeded(\n        RestMethodInfoInternal restMethodInfo,\n        Type[]? genericArgumentTypes) =>\n        genericArgumentTypes is { } genericArguments\n            ? _interfaceGenericHttpMethods.GetOrAdd(\n                new(restMethodInfo.MethodInfo, genericArguments),\n                static (_, state) =>\n                    new RestMethodInfoInternal(\n                        state.RestMethod.Type,\n                        state.RestMethod.MethodInfo.MakeGenericMethod(state.GenericArguments),","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit.Reflection/RequestBuilderImplementation.cs#L393-L429","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Check the generic constraints on the interface method and ensure the type argument satisfies them.","Verify the parameterTypes you pass match the overload's signature exactly (order, count, types).","If the inner closure threw a constraint error, test closing the generic yourself in a unit test to surface the real message."],"exampleFix":"// before\npublic interface IApi {\n    [Post(\"/items\")] Task PostAsync<T>([Body] T item) where T : class;\n}\nawait api.PostAsync(123); // int violates 'where T : class' -> swallowed -> No suitable Method found\n\n// after\nawait api.PostAsync(new Item { ... }); // reference type satisfies constraint","handlingStrategy":"validation","validationCode":"// Verify generic constraints yourself before calling.\nstatic void AssertSatisfies<TMethod>(Type genericArg) where TMethod : class {\n    var constraints = typeof(TMethod).GetGenericArguments()[0].GetGenericParameterConstraints();\n    foreach (var c in constraints)\n        if (!c.IsAssignableFrom(genericArg))\n            throw new InvalidOperationException($\"{genericArg} violates constraint {c}.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match the method's generic constraints when picking type arguments.","Ensure parameterTypes align with the overload signature.","Unit-test generic method closure to surface the real constraint error."],"tags":["refit","generic","reflection","design-time"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}