Skip to content

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

Closed

Description

@georgy93

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?

Activity

  1. clairernovotny commented on Mar 3, 2021

    @clairernovotny
    Member

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

  2. georgy93 commented on Mar 4, 2021

    @georgy93
    Author

    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.
  3. brainwipe commented on Jan 5, 2023

    @brainwipe

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

  4. added
    🟢 priority: low
    🧬 area: source-gen
    on Jun 16, 2026
  5. glennawatson commented on Jun 16, 2026

    @glennawatson
    Contributor

    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.

  6. glennawatson commented on Jul 15, 2026

    @glennawatson
    Contributor

    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.

    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.
  7. github-actions commented on Jul 30, 2026

    @github-actions

    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.

  8. locked as resolved and limited conversation to collaborators on Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bug🟢 priority: low🧬 area: source-gen

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions