PIAB: Is this a Bug? Exception is thrown when invoke PolicyInjection.Wrap<IInterface>(IInterface instance)

Topics: Policy Injection Application Block
May 29, 2008 at 6:55 AM
A reflection related exception must be thrown when we invoke PolicyInjection.Wrap<IInterface>(IInterface instance) if IInterface inherits another interface. E.g.
public interface IContractBase

public interface IConntract:IContractBase

static void Main()
    IConntract instance = Factory.Create();
   PolicyInjection.Wrap<IContract>(instance );

An exception will be thrown, with error message is like this: "'this' type cannnot be a interface itself".

After debuggging aginst PIAB source code, I found the error occurs when execute the GetMethodSet Method of Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Policy class.  Furthermore, the line of source code to cause this error is located here:

InterfaceMapping mapping = member.DeclaringType.GetInterfaceMap(itf);

It is obvious that the GetInterfaceMap method cannot be invoked if member.DeclaringType is a interface type itself.