refit
refit copied to clipboard
[BUG] Multiple interfaces with same name but different namespace
Describe the bug When trying to generate clients from multiple interfaces with the same name, but different namespaces, there seems to be a limit at two interfaces before nothing is generated.
Steps To Reproduce
- Create a project named
SampleClient
- Add an
ISampleClient
interface in theSampleClient.First
namespace with a[Get("/")] Task<string> GetAsync()
method - Add an
ISampleClient
interface in theSampleClient.Second
namespace with a[Get("/")] Task<HttpResponseMessage> GetAsync()
method - Add an
ISampleClient
interface in theSampleClient.Third
namespace with a[Get("/")] Task<ApiResponse<string>> GetAsync()
method - Try to obtain clients for the three interfaces with
RestService.For<T>()
Expected behavior
All three interfaces should generate a different client and work with RestService.For<T>()
Environment
- OS: Windows 10 / Ubuntu 20.04
- Device: NA
- Version: 6.1.15
- Working Version:
Additional context
- An error "T doesn't look like a Refit interface. Make sure it has at least one method with a Refit HTTP method attribute and Refit is installed in the project." is thrown.
- Debugging shows that after the third interface is added, clients in the
Refit.Internal.Generated
namespace are not generated anymore. - Everything works as expected when only two interfaces are present in the project.
Just noticed the same issue, is there any workaround for this? Except of renaming all the interfaces.
I am running into the same issue, after switching from RestEase, where this is no issue. I Want to switch to Refit to use System.Text.Json instead of Newtonsoft.Json, because now I have a mix of them both due to different dependencies.
So I have the same question as @Almis90; is there a way to work around this, except for renaming all my interfaces?
P.S. the message Visual studio gives is Warning CS8785 Generator 'InterfaceStubGeneratorV2' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName 'IShelly1.g.cs' of the added source file must be unique within a generator.
I am trying to fix this and hope to have a PR soon.