Skip to content

[Bug]: AddRefitGeneratedClient fails for methods with query parameters #2185

Closed

Description

@RoccoZero

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

  1. glennawatson commented on Jul 1, 2026

    @glennawatson
    Contributor

    Thanks for the report.

    Two fold fix.

  2. added
    🔴 priority: high
    🧬 area: source-gen
    on Jul 1, 2026
  3. RoccoZero commented on Jul 3, 2026

    @RoccoZero
    Author

    Update: I tested this again with Refit 13.1.0 and found that explicit query placeholders now work correctly:

    [Get("/signin?login={login}&password={password}")]
    Task<JsonNode> SignIn(string login, string password);

    However, the equivalent method using Refit's automatic query-parameter behavior still does not work with AddRefitGeneratedClient<T>():

    [Get("/signin")]
    Task<JsonNode> SignIn2(string login, string password);

    Calling SignIn2 throws NotSupportedException because the generated implementation still falls back to BuildRestResultFuncForMethod.

    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.

  4. glennawatson commented on Jul 3, 2026

    @glennawatson
    Contributor

    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.

  5. glennawatson commented on Jul 15, 2026

    @glennawatson
    Contributor

    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.

    Type-safe REST API clients for .NET, generated from annotated interfaces with build-time source generation, direct request construction, System.Text.Json defaults, and support for trimming and AOT.
  6. RoccoZero commented on Jul 16, 2026

    @RoccoZero
    Author

    Confirmed fixed with Refit 14.0.0-beta.1. AddRefitGeneratedClient() now works correctly with query parameters in my NativeAOT application. Thank you!

  7. github-actions commented on Jul 31, 2026

    @github-actions

    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.

  8. locked as resolved and limited conversation to collaborators on Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature🐛 bug🔴 priority: high🧬 area: source-gen

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions