|
-
July 25th, 2002, 02:22 AM
#1
Casting Problem when loading from dll
Hi
I am trying to load at runtime a class from a dll,
knowing an interface that the class implements.
I can load and create an instance of that class,
but only as an Object... I cannot convert it to
my interface.
The error is: System.InvalidCastException
The code is:
Assembly a=Assembly.LoadFrom(("a.dll");
Type theType = a.GetType("Type1");
Type interfaceType=theType.GetInterface("iType1");
Console.WriteLine("implements {0}",interfaceType);
Object o=Activator.CreateInstance(theType);
Console.WriteLine("loaded as an object: {0}",o);
iType1 i = (iType1) o;
Console.WriteLine(i);
Both the dll and the exe have the same namespace,
and they both know the interface iType1. And both
the interface and the class are public...
Thanks in advance,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|