refit icon indicating copy to clipboard operation
refit copied to clipboard

[Bug]: Refit fails to generate if more than two types have the same name

Open yoelhalb-hitech opened this issue 2 years ago • 2 comments

Describe the bug 🐞

When having more than two Refit interfaces with the same name in the same project (but different namespaces or different enclosing type) the generator will fail to generate the classes.

The warning at compile time is:

CSC : 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 'ITest1.g.cs' of the added source file must be unique within a generator.

While at runtime it fails with:

System.InvalidOperationException : ITest 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.

Step to reproduce

namespace A
{
	public interface ITest
	{
		[Post("/")]
		public Task<object> Test1(object test);
	}
}

namespace B
{
	public interface ITest
	{
		[Post("/")]
		Task<object> Test2(object test);
	}
}

namespace C
{
	public interface ITest
	{
		[Post("/")]
		Task<object> Test3(object test);
	}
}

Reproduction repository

No response

Expected behavior

  • Should work perfectly

  • Otherwise it should at the minimum:

    • Give a descriptive error (not just a warning) at compile time (and in case a user doesn't want it as an error there might be an option in the csproj to remove it, and this can be mentioned in the error message, but by default a novice user expects Refit to work...)
    • Also the error message at runtime should mention the possibility that the source generation failed (otherwise users are left in the dark scratching their head).

Screenshots 🖼️

No response

IDE

Visual Studio 2022

Operating system

Windows 10

Version

No response

Device

No response

Refit Version

6.3.2

Additional information ℹ️

No response

yoelhalb-hitech avatar Jun 06 '23 23:06 yoelhalb-hitech

Can you contribute a PR that adds this as a test case?

anaisbetts avatar Jun 07 '23 07:06 anaisbetts

It actually looks like there are several test cases which check for something similar to this.

Should these tests be modified in some way so that they accurately check for 3 interfaces of the same name, instead of just 2?

chrstophr-wltrs avatar Dec 18 '23 17:12 chrstophr-wltrs