refit
refit copied to clipboard
[Bug]: exception with TrimMode full: "URL /path/{id} has parameter id, but no method parameter matches"
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
- Add
<TrimMode>full</TrimMode>to any Refit-based .NET8 iOS project into Release configuration - Compile and deploy to a device or simulator
- Start the app
- Expect a crash on the moment of API services creation
- 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.
This seems to be related to https://github.com/reactiveui/refit/issues/1389
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