tags:

views:

318

answers:

1

I fail to see the reason why this code fails (Error binding to target method.)

    public interface Interface
    {}

    public class Implementation : Interface
    {}

    public class Program
    {
      public static void Main()
      {
        Invoke();
      }

      public Interface SomeMethod(object arg)
      {
          return new Implementation();
      }

      public void Invoke()
      {
        Delegate someMethod = Delegate.CreateDelegate(typeof(Func<Interface, object>), this, "SomeMethod");
      }
    }

Tried different overloads of CreateDelegate with the same result: when the target method returns an interface type, binding the delegate to the method fails. Can anyone shed some light on this?

+7  A: 

Your template parameters are backwards, It should be Func<object,Interface>

thestar