Reflection Problems...
-
Hello everybody! First I´m sorry about my english, I come from germany. I have a little obscure problem with reflection. I created a own class with only one constructor -> private static System.Reflection.Assembly assembly; public MyReflection(string dllfilename) { assembly = System.Reflection.Assembly.LoadFrom(dllfilename); //** // do something with assembly (this part works fine!) } In my main application I´m creating an object from this class like: MyReflection myRefl = new MyReflection(dllfilename); I choosed that a user can change the assembly file (for example to actualize it) in my main application and the code line "MyReflection ... = new ..." is recalled with the different dllfilename. If I debug MyReflection class it is working fine until the line signed with //**. I can recrate the object how many times I want, but it keeps the first assembly file. Why? Why doesn´t actualize my computer this file (the string "dllfilename" is always appearing correctly!) Is it a problem with the garbage collector? And if this is true, how can I definetely force that C# destroys an object? It would be nice if someone is answering to me.. Ciao Norman-Timo
-
Hello everybody! First I´m sorry about my english, I come from germany. I have a little obscure problem with reflection. I created a own class with only one constructor -> private static System.Reflection.Assembly assembly; public MyReflection(string dllfilename) { assembly = System.Reflection.Assembly.LoadFrom(dllfilename); //** // do something with assembly (this part works fine!) } In my main application I´m creating an object from this class like: MyReflection myRefl = new MyReflection(dllfilename); I choosed that a user can change the assembly file (for example to actualize it) in my main application and the code line "MyReflection ... = new ..." is recalled with the different dllfilename. If I debug MyReflection class it is working fine until the line signed with //**. I can recrate the object how many times I want, but it keeps the first assembly file. Why? Why doesn´t actualize my computer this file (the string "dllfilename" is always appearing correctly!) Is it a problem with the garbage collector? And if this is true, how can I definetely force that C# destroys an object? It would be nice if someone is answering to me.. Ciao Norman-Timo
Are you trying to load a different version of the same assembly? If so, if you havn't strong named the assmebly the CLR class loader will disregard the version number of the assembly. To perform this operation safely so you don't have to deal with file locking, take a look at
AppDomain.ShadowCopyFiles
as this is implemented by fusion and also used in ASP.NET. At least load the assembly into it's ownAppDomain
which will allow you to safely unload theAppDomain
when you are done with the assembly. - Nick Parker
My Blog | My Articles