E
eric_mamet_test
I am trying to create a class at runtime from some library and call its
method dynamically but it keeps failing when calling the method...
In a separate DLL, I have a class as follows
namespace MyClassLibrary
{
public class SimpleClass
{
public string SayHello()
{
return "Hello";
}
}
}
In a console app, I load an assembly from my DLL file, create a
SimpleClass object
myAssembly = Assembly.LoadFrom(MyDLLFilename);
object someObject =
myAssembly.CreateInstance("MyClassLibrary.SimpleClass");
so far so good, it looks like someObject is created
but then it fails if I try to cast my object to a SimpleClass in order
to call its properties...
string MyString = ((MyClassLibrary.SimpleClass) someObject).SayHello();
Either there is a bug or I don't understand (I suspect the second!)
Thanks for any help
Eric
method dynamically but it keeps failing when calling the method...
In a separate DLL, I have a class as follows
namespace MyClassLibrary
{
public class SimpleClass
{
public string SayHello()
{
return "Hello";
}
}
}
In a console app, I load an assembly from my DLL file, create a
SimpleClass object
myAssembly = Assembly.LoadFrom(MyDLLFilename);
object someObject =
myAssembly.CreateInstance("MyClassLibrary.SimpleClass");
so far so good, it looks like someObject is created
but then it fails if I try to cast my object to a SimpleClass in order
to call its properties...
string MyString = ((MyClassLibrary.SimpleClass) someObject).SayHello();
Either there is a bug or I don't understand (I suspect the second!)
Thanks for any help
Eric