refit icon indicating copy to clipboard operation
refit copied to clipboard

Refit code generation doesn't work with extern aliases

Open georgy93 opened this issue 4 years ago • 3 comments

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?

georgy93 avatar Mar 03 '21 09:03 georgy93

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

clairernovotny avatar Mar 03 '21 13:03 clairernovotny

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
Contribute to georgy93/RefitCodeGenIssuesWithExternAlias development by creating an account on GitHub.

georgy93 avatar Mar 04 '21 10:03 georgy93

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

brainwipe avatar Jan 05 '23 13:01 brainwipe