2

We use Refit for our API declarations and want to use Interface inheritance. A sample is shown here: https://github.com/reactiveui/refit#interface-inheritance

public interface IPlatformRestClient
{
    HttpClient Client { get; }

    [Get("/version")]
    Task<string> GetVersion();
}

public interface ITestRestClient : IPlatformRestClient
{
    [Get("/test")]
    Task<string> Test();
}

I may be blind and do something wrong, but the construct results in the following error message

'AutoGeneratedITestRestClient' does not implement interface member 'IPlatformRestClient.GetVersion()' Platform.RestClient.UnitTests

And if I open the stubs:

/// <inheritdoc />
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[Preserve]
[global::System.Reflection.Obfuscation(Exclude=true)]
partial class AutoGeneratedITestRestClient : ITestRestClient
{
    /// <inheritdoc />
    public HttpClient Client { get; protected set; }
    readonly IRequestBuilder requestBuilder;

    /// <inheritdoc />
    public AutoGeneratedITestRestClient(HttpClient client, IRequestBuilder requestBuilder)
    {
        Client = client;
        this.requestBuilder = requestBuilder;
    }

    /// <inheritdoc />
    Task<string> ITestRestClient.Test()
    {
        var arguments = new object[] {  };
        var func = requestBuilder.BuildRestResultFuncForMethod("Test", new Type[] {  });
        return (Task<string>)func(Client, arguments);
    }
}

So is this feature broken or do I have any error?

Benjamin Abt
  • 1,730
  • 18
  • 33
  • 1
    Looks like a bug. Interface inheritance works only if all interfaces are located in one project – Benjamin Abt Apr 14 '19 at 13:06
  • 2
    this is an [open Issue](https://github.com/reactiveui/refit/issues/650) for Refit library as interface inheritance works only in case if they are in the same project. – Naushad Warsi Dec 06 '19 at 03:53
  • 1
    @NaushadWarsi nice to see you again. You found my GitHub issue :-) – Benjamin Abt Dec 06 '19 at 17:32
  • 3
    thanks for this post! I am having a similar problem with inherited interfaces. I really needed this to work, so the quick fix was to declare all methods from the parent interface in the child interface as new. Defeats the purpose of inheritance but I am glad I have found this post and the bug reference so I can keep an eye on that fix. – leosteffen Feb 24 '20 at 16:12

0 Answers0