I made a private assembly callled CarLibrary (CarLibrary.dll). Then I created a client console application and added the reference of CarLibrary , below is the main method of console application
using CarLibrary;
...
static void Main(string[] args)
{
SportsCar s = new SportsCar(); //CarLibrary contains a type-SportsCar class
Type t = s.GetType();
MethodInfo[] mi = t.GetMethods();
foreach (MethodInfo m in mi)
{
...
}
}
it worked, but if I change the main method to :
static void Main(string[] args)
{
string typeName = "CarLibrary.SportsCar";
Type t = Type.GetType(typeName);
// Reflection doesn't work
}
why it doesn't work in this way, I did add reference of CarLibrary.dll, and the manifest of client console application does have
.assembly extern CarLibrary
{ ... }
so in runtime, the CLR should find CarLibrary.dll and load it into memory, Refelction should work!
and if I change it as:
string typeName = "System.Int32";
Type t = Type.GetType(typeName);
it does work. I'm really confused.
Aucun commentaire:
Enregistrer un commentaire