G
Guest
Hi all, when trying to load and create an instance from an assembly I'm getting InvalidCastException. Here's a chunk of code
Assembly cAssembly = Assembly.LoadFrom("d:\\DAOTest.dll")
object cDAOInstance = null
foreach (Type cType in cAssembly.GetTypes()
if ((cType.IsClass == true) && (cType.FullName == "DAOTest.CustomerRowSet")
cDAOInstance = Activator.CreateInstance(cType)
// this line generates the InvalidCastExceptio
//((DAOTest.CustomerRowSet)cDAOInstance).getTraderList()
CustomerRowSet rs = new CustomerRowSet()
Type t1 = cDAOInstance.GetType()
Type t2 = rs.GetType()
Console.WriteLine(t1.ToString())
Console.WriteLine(t2.ToString())
Strangely, the result in the console for the ToString calls is
DAOTest.CustomerRowSe
DAOTest.CustomerRowSe
Any info/advice on resolving this problem ? Many thanks in advance
Chris
Assembly cAssembly = Assembly.LoadFrom("d:\\DAOTest.dll")
object cDAOInstance = null
foreach (Type cType in cAssembly.GetTypes()
if ((cType.IsClass == true) && (cType.FullName == "DAOTest.CustomerRowSet")
cDAOInstance = Activator.CreateInstance(cType)
// this line generates the InvalidCastExceptio
//((DAOTest.CustomerRowSet)cDAOInstance).getTraderList()
CustomerRowSet rs = new CustomerRowSet()
Type t1 = cDAOInstance.GetType()
Type t2 = rs.GetType()
Console.WriteLine(t1.ToString())
Console.WriteLine(t2.ToString())
Strangely, the result in the console for the ToString calls is
DAOTest.CustomerRowSe
DAOTest.CustomerRowSe
Any info/advice on resolving this problem ? Many thanks in advance
Chris