23maploosh
Programmer
I am trying to understand the concept of reflection and found a tutorial on the web. I thought I understood it until I started to play with it a little further. I created a winform app named 'reflectiontesting'. I also created a simple class called 'clsCar' that simply overrides the toString() method and displays 'I am a car'. I have two buttons on the form. The first buttons loops through all of the assemblies in the current app domain and simply prints out their type. Here is the code:
foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
{
MessageBox.Show(assem.ToString());
}
The second button creates an instance of the Car class and then calls its toString method. Here is the code for that.
System.Reflection.Assembly assem = System.Reflection.Assembly.Load("ReflectionTesting");
Object c = assem.CreateInstance("reflectionTesting.clsCar");
MessageBox.Show(c.ToString());
After running and playing with this code I thought I started to understand the concept. I then went into my debug directory for this assembly and renamed the executable to 'reflectiontesting99.exe'. Once I did this and clicked button2 I received a FileNotFound Exception. I then clicked button1 and it showed that the assembly ReflectionTesting was still loaded.
I am just wondering why changing the executable name after it has been produced causes this error?
Thanks
Matt
foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
{
MessageBox.Show(assem.ToString());
}
The second button creates an instance of the Car class and then calls its toString method. Here is the code for that.
System.Reflection.Assembly assem = System.Reflection.Assembly.Load("ReflectionTesting");
Object c = assem.CreateInstance("reflectionTesting.clsCar");
MessageBox.Show(c.ToString());
After running and playing with this code I thought I started to understand the concept. I then went into my debug directory for this assembly and renamed the executable to 'reflectiontesting99.exe'. Once I did this and clicked button2 I received a FileNotFound Exception. I then clicked button1 and it showed that the assembly ReflectionTesting was still loaded.
I am just wondering why changing the executable name after it has been produced causes this error?
Thanks
Matt