Cast and Activator.CreateInstance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vincent Lascaux

    #1

    Cast and Activator.CreateInstance

    Hello,

    I have two assemblies A and B and an IFoo empty interface

    In the assembly B there is the following code :
    namespace B
    {
    public class Foo : IFoo { }
    }

    In the assembly A there is :
    namespace A
    {
    public class Bar
    {
    Assembly a = Assembly.LoadFr om("B.dll");
    Type FooType = a.GetType("B.Fo o");
    IFoo foo = (IFoo)Activator .CreateInstance (FooType); // Error
    }
    }

    I get the following run time error : (sorry, it may not be the exact words
    since I translate from french)
    An unhandled exception of type 'System.Invalid CastException' has happened in
    A.exe
    The specificated cast spécifié is not valid.

    Can you help me ?

    Thanks

    --
    Vincent


  • Vincent Lascaux

    #2
    Re: Cast and Activator.Creat eInstance

    I solved the problem :
    Both A and B projects included the same file that described the foo
    interface
    I created a Foo assembly that export the foo interface and is referenced in
    A and B and it works...

    --
    Vincent


    Comment

    Working...