Delegates .CreateDelegate fails when return type is interface

I see no reason why this code is not working (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 CreateDelegate overloads with the same result: when the target method returns an interface type, the delegate binding to the method fails. Can anyone shed some light on this?

0


a source to share


1 answer


Template parameters back, Should be Func<object,Interface>



+7


a source







All Articles