Repository navigation
Description
Describe the bug 🐞
AddRefitGeneratedClient<T>() throws NotSupportedException at runtime when a generated Refit method contains query parameters.
Minimal interface:
public interface IAuthRestApi
{
[Get("/signin")]
Task<JsonNode> SignIn(
[AliasAs("login")] string login,
[AliasAs("password")] string password);
}Registration:
[JsonSerializable(typeof(JsonNode))]
public partial class ApiJsonSerializerContext : JsonSerializerContext
{
}
var settings = new RefitSettings
{
ContentSerializer = new SystemTextJsonContentSerializer(
ApiJsonSerializerContext.Default.Options)
};
services
.AddRefitGeneratedClient<IAuthRestApi>(settings)
.ConfigureHttpClient(client =>
client.BaseAddress = new Uri("https://api.example.com"));Calling:
await api.SignIn("login", "password");throws:
System.NotSupportedException: This Refit client was created with the generated-only API, but the generated client needs the reflection request builder for 'SignIn'. Enable generated request building for this method or use RestService.For when reflection is acceptable.
at Refit.GeneratedOnlyRequestBuilder.BuildRestResultFuncForMethod(...)
at Refit.Implementation.Generated.IAuthRestApi.SignIn(...)
The source generator creates IAuthRestApi.g.cs, but the generated SignIn implementation still uses the reflection-based path:
var refitFunc = refitRequestBuilder.BuildRestResultFuncForMethod(
"SignIn",
parameterTypes);The same problem occurs when query parameters are explicitly included in the route:
[Get("/signin?login={login}&password={password}")]
Task<JsonNode> SignIn(string login, string password);RefitGeneratedRequestBuilding is true, DisableRefitSourceGenerator is not enabled, and source-generated System.Text.Json metadata is provided for JsonNode.
A parameterless method returning the same JsonNode type is generated correctly through GeneratedRequestRunner.SendAsync, so the problem does not appear to be caused by JsonNode or JSON serialization. Other methods containing ordinary query parameters also fall back to BuildRestResultFuncForMethod.
Expected behavior: the source generator should generate request construction for ordinary route and query parameters so the interface can be used through AddRefitGeneratedClient<T>() in NativeAOT applications without reflection. If this method shape is intentionally unsupported, the analyzer should report a compile-time diagnostic explaining that the method is incompatible with generated-only registration instead of allowing registration and failing only at runtime.
Tested with:
- Refit 12.1.0
- Refit.HttpClientFactory 12.1.0
- .NET 10
- NativeAOT
Step to reproduce
Step to reproduce: See the complete reproduction steps in the bug description above.
Reproduction repository
https://github.com/reactiveui/refit
Expected behavior
See the expected behavior in the bug description above.
Screenshots 🖼️
No response
IDE
No response
Operating system
No response
Version
No response
Device
No response
Refit Version
No response
Additional information ℹ️
No response
Activity
glennawatson commentedon Jul 1, 2026
Thanks for the report.
Two fold fix.
RoccoZero commentedon Jul 3, 2026
Update: I tested this again with Refit 13.1.0 and found that explicit query placeholders now work correctly:
However, the equivalent method using Refit's automatic query-parameter behavior still does not work with
AddRefitGeneratedClient<T>():Calling
SignIn2throwsNotSupportedExceptionbecause the generated implementation still falls back toBuildRestResultFuncForMethod.Therefore, the issue in Refit 13.1.0 appears to be specifically related to automatic query-string generation for method parameters. Explicit query placeholders are generated correctly, while implicit query parameters still require the reflection request builder.
glennawatson commentedon Jul 3, 2026
Thanks for the update.
Yeah explicitly haven't gotten around to this issue yet, it's on the plan in the next week or so.
feat!: reflection-free source-generated request building (#2210)
glennawatson commentedon Jul 15, 2026
This is addressed in the Refit 14 beta, now available on NuGet: https://www.nuget.org/packages/Refit/14.0.0-beta.1
Please give it a try - feedback ahead of the stable 14.0.0 release is very welcome.
RoccoZero commentedon Jul 16, 2026
Confirmed fixed with Refit 14.0.0-beta.1. AddRefitGeneratedClient() now works correctly with query parameters in my NativeAOT application. Thank you!
github-actions commentedon Jul 31, 2026
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.