The other day I was working on an interceptor that listened to calls to some Services and redirected the calls to services hosted on remote machine, instead of running it locally when strangest thing happened. I was trying to find and invoke existing methods on my interface that according to reflection, were not there. Those services were using inherited interface:

1
2
3
4
5
6
7
8
9
10
11
public interface IServiceBase<T>
{
T FindOne(Criteria c);

T[] FindMany(Criteria c);
}

public interface ICustomerService : IServiceBase<Customer>
{
Customer FindByName(string name);
}

I was trying to get methods of ICustomerSerivce defined and inherited from the base interface:

1
2
3
4
5
6
7
8
[TestMethod]
public void Can_Find_Base_Method_On_Interface()
{
var service = typeof (ICustomerService);
var method = service.GetMethod("FindOne");

Assert.IsNotNull(method);
}

Unfortunately, this fails! It seems reflection does not work consistently on inherited interfaces. To solve this, you’d have all the base methods redefined, which becomes very nasty if you have multiple interface inheritances, or if you extensively use generics on interface level. So changing the above code to this will make the test go green:

1
2
3
4
5
6
7
8
public interface ICustomerService : IServiceBase<Customer>
{
Customer FindByName(string name);

new Customer FindOne(Criteria c);

new Customer[] FindMany(Criteria c);
}

I still don’t know why this behavior, or maybe this is a known issue?

Update: Found out that the behavior in fact is inline with ECMA CLI specifications. You can however check the methods on Interface’s other interfaces. See a solution here