Skip to content

[Bug]: IGitHubApi 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. #1920

@ViniciusCestarii

Description

@ViniciusCestarii

Describe the bug 🐞

Refit.RestService.For throws an error if the name of the file .csproj has special characters like - @.

To fix it just rename your .csproj file removing special characters (_ is supported)

Example: Refit-Test.csproj ~> RefitTest.csproj

This issue seems to arise because Refit's code generation depends on the project name, which may cause invalid namespaces or class names in generated code when special characters are present.

It would be helpful if Refit could:

  • Check and throw an error with a message about special characters on .csproj file.

OR

  • Sanitize the name of .csproj file for generating code

OR at least

  • Include a note in the documentation about valid .csproj naming conventions when using Refit.

I created this issue is so that people who are facing this very specific problem to find the solution here.

Step to reproduce

using System;
using System.Threading.Tasks;
using Refit;

namespace RefitTest
{
    public class MainClass
    {
        public static async Task Main(string[] args)
        {
            var gitHubApi = RestService.For<IGitHubApi>("https://api.github.com");
            var user = await gitHubApi.GetUser("ViniciusCestarii");
            Console.WriteLine(user);

        }
    }

    public interface IGitHubApi
    {
        [Headers("User-Agent: My Favorite User Agent!")]
        [Get("/users/{user}")]
        Task<object> GetUser(string user);
    }
}

Refit-Test.csproj

dotnet run

Reproduction repository

No response

Expected behavior

This should happen...

Screenshots 🖼️

No response

IDE

No response

Operating system

No response

Version

No response

Device

No response

Refit Version

8.0.0

Additional information ℹ️

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions