refit icon indicating copy to clipboard operation
refit copied to clipboard

[BUG] Multiple interfaces with same name but different namespace

Open outofrange-consulting opened this issue 3 years ago • 3 comments

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

  1. Create a project named SampleClient
  2. Add an ISampleClient interface in the SampleClient.First namespace with a [Get("/")] Task<string> GetAsync() method
  3. Add an ISampleClient interface in the SampleClient.Second namespace with a [Get("/")] Task<HttpResponseMessage> GetAsync() method
  4. Add an ISampleClient interface in the SampleClient.Third namespace with a [Get("/")] Task<ApiResponse<string>> GetAsync() method
  5. 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.

outofrange-consulting avatar Oct 25 '21 14:10 outofrange-consulting

Just noticed the same issue, is there any workaround for this? Except of renaming all the interfaces.

Almis90 avatar Oct 31 '21 17:10 Almis90

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.

dtewinkel avatar Mar 12 '23 15:03 dtewinkel

I am trying to fix this and hope to have a PR soon.

dtewinkel avatar Jul 20 '23 19:07 dtewinkel