You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refit code generation doesn't work with extern aliases #1101
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?
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 ==========
Confirmed still relevant on current main: the source generator (InterfaceStubGenerator.Shared/Parser.cs) emits types via SymbolDisplayFormat.FullyQualifiedFormat, which prefixes global:: but cannot express extern aliases. Extern-aliased types live in a separate alias root that global:: doesn't reach, so the generated stub references the wrong/ambiguous symbol and fails to compile (the CS0234/CS0535 errors in the repro).
Labeled as a source-gen bug. Niche, so low priority. A fix would need the generator to detect when a referenced type comes from a non-global alias and emit the appropriate alias-qualified name (plus the extern alias directive) in the generated file.
Type-safe REST API clients for .NET, generated from annotated interfaces with build-time source generation, direct request construction, System.Text.Json defaults, and support for trimming and AOT.
Activity
clairernovotny commentedon Mar 3, 2021
Extern alias should work with v6. Do you have a repro?
georgy93 commentedon Mar 4, 2021
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 ==========
brainwipe commentedon Jan 5, 2023
This is happening for us on 6.3.2.
Any update on a fix?
glennawatson commentedon Jun 16, 2026
Confirmed still relevant on current main: the source generator (InterfaceStubGenerator.Shared/Parser.cs) emits types via
SymbolDisplayFormat.FullyQualifiedFormat, which prefixesglobal::but cannot express extern aliases. Extern-aliased types live in a separate alias root thatglobal::doesn't reach, so the generated stub references the wrong/ambiguous symbol and fails to compile (the CS0234/CS0535 errors in the repro).Labeled as a source-gen bug. Niche, so low priority. A fix would need the generator to detect when a referenced type comes from a non-global alias and emit the appropriate alias-qualified name (plus the
extern aliasdirective) in the generated file.feat!: reflection-free source-generated request building (#2210)
glennawatson commentedon Jul 15, 2026
This is addressed in the Refit 14 beta, now available on NuGet: https://www.nuget.org/packages/Refit/14.0.0-beta.1
Please give it a try - feedback ahead of the stable 14.0.0 release is very welcome.
github-actions commentedon Jul 30, 2026
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.