I am not able to create instance of an object using reflection (late binding)
The code is as follows.
Assembly myAssembly = Assembly.LoadFrom("C:\\dev20\\dll\\pwyUserSVCSLib.dll");
Type Atype = myAssembly.GetTypes()[0];
ObjectHandle objass = Activator.CreateInstance(myAssembly.FullName,Atype.FullName);
object[] args = {"qrg3sf55ehabzgqqxapk1p45","136304FE-646E-4483-A453-368981627C47"};
object result;
object objtarget = (object)objass.Unwrap();
BindingFlags flags = (BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance);
result = Atype.InvokeMember("Logoff",flags,null,objtarget,args);
Console.WriteLine("The result is '{0}'",result);
}
I get an error Invalid target type.
what's wrong with this code? Pl suggest.
Thanx
The code is as follows.
Assembly myAssembly = Assembly.LoadFrom("C:\\dev20\\dll\\pwyUserSVCSLib.dll");
Type Atype = myAssembly.GetTypes()[0];
ObjectHandle objass = Activator.CreateInstance(myAssembly.FullName,Atype.FullName);
object[] args = {"qrg3sf55ehabzgqqxapk1p45","136304FE-646E-4483-A453-368981627C47"};
object result;
object objtarget = (object)objass.Unwrap();
BindingFlags flags = (BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance);
result = Atype.InvokeMember("Logoff",flags,null,objtarget,args);
Console.WriteLine("The result is '{0}'",result);
}
I get an error Invalid target type.
what's wrong with this code? Pl suggest.
Thanx