Describe the bug 🐞
So after updating to Refit 12 and when having the following properties in the project:
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
The App won't build as the generated files from the interfaces have RequiresUnreferencedCodeAttribute on them and there is no good way to mark consuming code with the same attributes.
So IL2026 errors will be generated for each interface like:
Using member 'Refit.IRequestBuilder.BuildRestResultFuncForMethod(String, Type[], Type[])' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Building request delegates from reflected method metadata requires generic method metadata to be available at runtime. [/Users/tomaszcielecki/git/App/src/Data/Data.csproj]
So if I have interface IMyApi then the generated IMyApi.g.cs will have this error.
I am using Refit.HttpClientFactory, but doesn't seem to be related to this, as for the HttpClientFactory extension methods I can apply attributes.
Step to reproduce
- Enable
TreatWarningsAsErrors and EnableTrimAnalyzer
- Implement Refit interface
- Build app
Reproduction repository
Expected behavior
I would love for a way to handle the trimming warning. There is no way to add [RequiresUnreferencedCode] attribute on the interface, as it is only allowed on class, ctor and methods.
The only way I can handle the warning is to disable WarningsAsErrors on IL2026, which isn't ideal. I did try to add a rule to .editorconfig but it doesn't apply to these files as they are only spat out in obj folder.
Screenshots 🖼️
No response
IDE
No response
Operating system
No response
Version
No response
Device
No response
Refit Version
12.1.0+
Additional information ℹ️
No response
Describe the bug 🐞
So after updating to Refit 12 and when having the following properties in the project:
The App won't build as the generated files from the interfaces have
RequiresUnreferencedCodeAttributeon them and there is no good way to mark consuming code with the same attributes.So IL2026 errors will be generated for each interface like:
So if I have interface
IMyApithen the generatedIMyApi.g.cswill have this error.I am using
Refit.HttpClientFactory, but doesn't seem to be related to this, as for the HttpClientFactory extension methods I can apply attributes.Step to reproduce
TreatWarningsAsErrorsandEnableTrimAnalyzerReproduction repository
Expected behavior
I would love for a way to handle the trimming warning. There is no way to add
[RequiresUnreferencedCode]attribute on the interface, as it is only allowed on class, ctor and methods.The only way I can handle the warning is to disable WarningsAsErrors on IL2026, which isn't ideal. I did try to add a rule to .editorconfig but it doesn't apply to these files as they are only spat out in obj folder.
Screenshots 🖼️
No response
IDE
No response
Operating system
No response
Version
No response
Device
No response
Refit Version
12.1.0+
Additional information ℹ️
No response