reactiveui / refit

The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface.
https://reactiveui.github.io/refit/
MIT License
8.47k stars 745 forks source link

Refit code generation doesn't work with extern aliases #1101

Open georgy93 opened 3 years ago

georgy93 commented 3 years ago

Hello!

I'm having trouble implementing Refit into a project I'm working on, because one of the interfaces used for Rest communication is using "extern alias" . It is needed because otherwise we are having conflicts with namespaces and classes from company nuggets we are referencing.

However, the extern alias seems to break code generation and I'm getting compile time errors from Refit.

Can detecting & resolving extern aliases be done in the scope of Refit library?

clairernovotny commented 3 years ago

Extern alias should work with v6. Do you have a repro?

georgy93 commented 3 years ago

Hi Clair!

Here is a sample repo https://github.com/georgy93/RefitCodeGenIssuesWithExternAlias

In my original post, I forgot to mention that I'm using the latest version of Refit library.

Attempting to build this solution results in:

Build started... 1>------ Build started: Project: ClassLibrary1, Configuration: Debug Any CPU ------ 2>------ Build started: Project: ClassLibrary2, Configuration: Debug Any CPU ------ 2>ClassLibrary2 -> D:\repos\RefitCodeGenIssuesWithExternAlias\ClassLibrary2\bin\Debug\net5.0\ClassLibrary2.dll 1>ClassLibrary1 -> D:\repos\RefitCodeGenIssuesWithExternAlias\ClassLibrary1\bin\Debug\net5.0\ClassLibrary1.dll 3>------ Build started: Project: ConsoleApp5, Configuration: Debug Any CPU ------ 3>D:\repos\RefitCodeGenIssuesWithExternAlias\ConsoleApp5\InterfaceStubGenerator.Core\Refit.Generator.InterfaceStubGenerator\IRestInterface.g.cs(33,74,33,82): error CS0234: The type or namespace name 'Response' does not exist in the namespace 'ClassLibrary1' (are you missing an assembly reference?) 3>D:\repos\RefitCodeGenIssuesWithExternAlias\ConsoleApp5\InterfaceStubGenerator.Core\Refit.Generator.InterfaceStubGenerator\IRestInterface.g.cs(41,67,41,75): error CS0234: The type or namespace name 'Response' does not exist in the namespace 'ClassLibrary1' (are you missing an assembly reference?) 3>D:\repos\RefitCodeGenIssuesWithExternAlias\ConsoleApp5\InterfaceStubGenerator.Core\Refit.Generator.InterfaceStubGenerator\IRestInterface.g.cs(41,112,41,119): error CS0539: 'Generated.ConsoleApp5IRestInterface.GetData(Request)' in explicit interface declaration is not found among members of the interface that can be implemented 3>D:\repos\RefitCodeGenIssuesWithExternAlias\ConsoleApp5\InterfaceStubGenerator.Core\Refit.Generator.InterfaceStubGenerator\IRestInterface.g.cs(16,11,16,45): error CS0535: 'Generated.ConsoleApp5IRestInterface' does not implement interface member 'IRestInterface.GetData(Request)' 3>Done building project "ConsoleApp5.csproj" -- FAILED. ========== Build: 2 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

GitHub
georgy93/RefitCodeGenIssuesWithExternAlias
Contribute to georgy93/RefitCodeGenIssuesWithExternAlias development by creating an account on GitHub.
brainwipe commented 1 year ago

This is happening for us on 6.3.2. Any update on a fix?