Describe the bug 🐞
Hi.
Can you please check and fix the NativeAOT / trimming warnings in Refit?
When publishing my project with NativeAOT enabled, I get many IL2026, IL2104, and IL3053 warnings from Refit and Refit.HttpClientFactory.
I would be very grateful if these warnings could be fixed or reduced, because my project targets NativeAOT and these warnings are very annoying/noisy during build.
The main warning comes from:
Refit.IRequestBuilder.BuildRestResultFuncForMethod(String, Type[], Type[])
It is marked with RequiresUnreferencedCodeAttribute, and the generated Refit implementation calls it, which produces many warnings.
Example warnings:
ILC : Trim analysis warning IL2026: Refit.Implementation.Generated.DivineClientRestIAuthRestApi.<SignIn>d__6.MoveNext(): Using member 'Refit.IRequestBuilder.BuildRestResultFuncForMethod(String,Type[],Type[])' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Refit uses reflection to analyze interface methods. Ensure referenced interfaces and DTOs are preserved when trimming.
Refit.HttpClientFactory.dll : warning IL2104: Assembly 'Refit.HttpClientFactory' produced trim warnings.
Refit.dll : warning IL2104: Assembly 'Refit' produced trim warnings.
Refit.dll : warning IL3053: Assembly 'Refit' produced AOT analysis warnings.
SystemTextJsonContentSerializer.cs: Trim analysis warning IL2026: JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext.
Step to reproduce
I am using:
- Refit: 11.0.1
- Refit.HttpClientFactory: 11.0.1
- Target framework: net10.0
- NativeAOT enabled
- Create a .NET project that uses Refit.
- Enable NativeAOT / trimming.
- Add Refit interfaces and use source-generated Refit implementation.
- Publish/build the project.
- See NativeAOT / trimming warnings.
Reproduction repository
https://github.com/reactiveui/refit
Expected behavior
Refit should build cleanly with NativeAOT/trimming enabled, or provide an official NativeAOT-friendly way to avoid these warnings.
Ideally, source-generated Refit clients should not call APIs marked with RequiresUnreferencedCodeAttribute, such as:
Refit.IRequestBuilder.BuildRestResultFuncForMethod(String, Type[], Type[])
Also, JSON serialization should use JsonSerializerContext / JsonTypeInfo-based overloads where possible, so NativeAOT projects can avoid IL2026, IL2104, and IL3053 warnings.
Screenshots 🖼️
No response
IDE
Visual Studio 2022
Operating system
Windows 11
Version
No response
Device
No response
Refit Version
11.0.1
Additional information ℹ️
No response
Describe the bug 🐞
Hi.
Can you please check and fix the NativeAOT / trimming warnings in Refit?
When publishing my project with NativeAOT enabled, I get many
IL2026,IL2104, andIL3053warnings from Refit and Refit.HttpClientFactory.I would be very grateful if these warnings could be fixed or reduced, because my project targets NativeAOT and these warnings are very annoying/noisy during build.
The main warning comes from:
Refit.IRequestBuilder.BuildRestResultFuncForMethod(String, Type[], Type[])It is marked with
RequiresUnreferencedCodeAttribute, and the generated Refit implementation calls it, which produces many warnings.Example warnings:
Step to reproduce
I am using:
Reproduction repository
https://github.com/reactiveui/refit
Expected behavior
Refit should build cleanly with NativeAOT/trimming enabled, or provide an official NativeAOT-friendly way to avoid these warnings.
Ideally, source-generated Refit clients should not call APIs marked with
RequiresUnreferencedCodeAttribute, such as:Refit.IRequestBuilder.BuildRestResultFuncForMethod(String, Type[], Type[])Also, JSON serialization should use
JsonSerializerContext/JsonTypeInfo-based overloads where possible, so NativeAOT projects can avoidIL2026,IL2104, andIL3053warnings.Screenshots 🖼️
No response
IDE
Visual Studio 2022
Operating system
Windows 11
Version
No response
Device
No response
Refit Version
11.0.1
Additional information ℹ️
No response