refit icon indicating copy to clipboard operation
refit copied to clipboard

[Bug]: exception with TrimMode full: "URL /path/{id} has parameter id, but no method parameter matches"

Open entdark opened this issue 1 year ago • 2 comments
trafficstars

Describe the bug 🐞

Trying to use TrimMode with value full in an iOS .NET8 project in Release configuration. The app crashes on startup when we are creating an API service with Refit with exception: Terminating app due to uncaught exception 'System.ArgumentException', reason: 'URL /path/{id} has parameter id, but no method parameter matches (System.ArgumentException)

Step to reproduce

  1. Add <TrimMode>full</TrimMode> to any Refit-based .NET8 iOS project into Release configuration
  2. Compile and deploy to a device or simulator
  3. Start the app
  4. Expect a crash on the moment of API services creation
  5. Check Console app for the logs with the exception above

Reproduction repository

No response

Expected behavior

A trimmed app starts without crashes and all API services get registered without exception.

Screenshots 🖼️

No response

IDE

Visual Studio for Mac

Operating system

macOS

Version

Sonoma 14.0

Device

iPhone 12 mini

Refit Version

7.0.0

Additional information ℹ️

It works fine in Debug or without TrimMode in Release. There is also a workaround to add [AliasAs("id")] to each API method.

[Get("/path")]
Task<Response> GetPathAsync(int id, CancellationToken ct); // CRASH

[Get("/path")]
Task<Response> GetPathAsync([AliasAs("id")] int id, CancellationToken ct); // WORKS

But there are of lot of methods so it's better to be some global fix.

entdark avatar Feb 14 '24 09:02 entdark

This seems to be related to https://github.com/reactiveui/refit/issues/1389

hansmbakker avatar Jul 30 '24 13:07 hansmbakker

I have created a fully supported AOT, with no reflection and almost identical to Refit's usage. Just wonder if it has any help. https://www.nuget.org/packages/HttpClientFiller

HttpClient Filler Code Generate in C# - Refit like but support AOT

ghostnguyen avatar Feb 15 '25 09:02 ghostnguyen