Cast and Activator.CreateInstance

V

Vincent Lascaux

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.LoadFrom("B.dll");
Type FooType = a.GetType("B.Foo");
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.InvalidCastException' has happened in
A.exe
The specificated cast spécifié is not valid.

Can you help me ?

Thanks
 
V

Vincent Lascaux

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top