c# - InvalidCastException when casting dynamically to interface -


i have interface defined in assembly this:

namespace helloworlder {     public interface ihelloworld {         string sayhello();     } } 

in seperate assembly have class defined as:

using helloworlder;  public class helloworld : ihelloworld {     string ihelloworld.sayhello() {         return "hello, world!";     } } 

now trying invoke f# interactive invalid cast exception, here code trying consume dll:

#i __source_directory__ #r "helloworlder.dll"  open system open system.reflection open helloworlder     let asm = assembly.loadfrom(__source_directory__ + "\\helloworld.dll") let hwins = asm.createinstance("helloworld") :?> ihelloworld let res = hwins.sayhello() 

from can see should work, precaution see have implemented interface ihelloworld explicitly. i'm guessing there i'm missing cannot figure out why it's throwing cast exception.

it turns out had unbox object instead of casting it, , worked fine.

let hwins = asm.createinstance("helloworld") |> unbox<ihelloworld>


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

spring cloud - How to configure SpringCloud Eureka instance to point to https on non standard port -

javascript - Bootstrap Popover: iOS Safari strange behaviour -