G
Guest
What is the correct method by which to load an object from a DLL? If I have
an application called "DLLTest" and a class library project called "BigDLL",
and that BigDLL contains a class called "Cow", I do the following in DLLTest:
using BigDLL;
namespace DLLTest
{
Assembly loader = Assembly.LoadFile(PathToBigDLL.dll);
foreach (Type t in loader.GetTypes())
{
if (t.Name == "Cow")
{
Cow c = (Cow)loader.CreateInstance(t.FullName);
}
}
}
And for reference, Cow.cs in BigDLL contains the following:
namespace BigDLL
{
public class Cow
{
public Cow()
{
}
}
}
I am given the following exception at the line 'Cow c = (Cow)...':
Unable to cast object of type 'BigDLL.Cow' to type 'BigDLL.Cow'.
How are objects supposed to be loaded in such a situation? The purpose of
this exercise is to be able to load an updated version of Cow, if somebody
recompiles the BigDLL, we would load in the new DLL that was spit out by the
compiler. Is there a reason why this isn't possible, or am I just using the
wrong methods?
an application called "DLLTest" and a class library project called "BigDLL",
and that BigDLL contains a class called "Cow", I do the following in DLLTest:
using BigDLL;
namespace DLLTest
{
Assembly loader = Assembly.LoadFile(PathToBigDLL.dll);
foreach (Type t in loader.GetTypes())
{
if (t.Name == "Cow")
{
Cow c = (Cow)loader.CreateInstance(t.FullName);
}
}
}
And for reference, Cow.cs in BigDLL contains the following:
namespace BigDLL
{
public class Cow
{
public Cow()
{
}
}
}
I am given the following exception at the line 'Cow c = (Cow)...':
Unable to cast object of type 'BigDLL.Cow' to type 'BigDLL.Cow'.
How are objects supposed to be loaded in such a situation? The purpose of
this exercise is to be able to load an updated version of Cow, if somebody
recompiles the BigDLL, we would load in the new DLL that was spit out by the
compiler. Is there a reason why this isn't possible, or am I just using the
wrong methods?