L
Lauren Hines
Hello,
I have read numerous post stating that the only way to unload an assembly
(DLL in my case) is to create a separate AppDomain, load the assembly, then
unload it by calling AppDomain.Unload.
When trying to delete the DLL file I get an exception that access is denied.
When trying to copy over the DLL file, I get an exception that it is being
used by another process.
Can anyone tell me what is wrong with the following code?
Much obliged.
Lauren
// must create a domain for unloading
System.Security.Policy.Evidence baseEvidence =
AppDomain.CurrentDomain.Evidence;
System.Security.Policy.Evidence adevidence = new
System.Security.Policy.Evidence(baseEvidence);
AppDomain ad = AppDomain.CreateDomain("Test",adevidence);
Assembly SampleAssembly;
// FileInfoManager is the name of my dll
// I have tried both of the following lines
//SampleAssembly = Assembly.Load("FileInfoManager,Version=1.0.0.0");
SampleAssembly = ad.Load("FileInfoManager,Version=1.0.0.0");
//unload the dll
AppDomain.Unload(ad);
ad = null;
SampleAssembly = null;
string oldDLL = System.Windows.Forms.Application.StartupPath +
"\\FileInfoManager.dll";
string newDLL = System.Windows.Forms.Application.StartupPath +
"\\FileInfoManager2.dll";
try
{
File.Delete(oldDLL);
}
catch(Exception exc)
{
log.WriteEntry("Exception deleting file " + oldDLL + " : " +
exc.Message,System.Diagnostics.EventLogEntryType.Error);
}
File.Copy(newDLL,oldDLL,true);
File.Delete(newDLL);
I have read numerous post stating that the only way to unload an assembly
(DLL in my case) is to create a separate AppDomain, load the assembly, then
unload it by calling AppDomain.Unload.
When trying to delete the DLL file I get an exception that access is denied.
When trying to copy over the DLL file, I get an exception that it is being
used by another process.
Can anyone tell me what is wrong with the following code?
Much obliged.
Lauren
// must create a domain for unloading
System.Security.Policy.Evidence baseEvidence =
AppDomain.CurrentDomain.Evidence;
System.Security.Policy.Evidence adevidence = new
System.Security.Policy.Evidence(baseEvidence);
AppDomain ad = AppDomain.CreateDomain("Test",adevidence);
Assembly SampleAssembly;
// FileInfoManager is the name of my dll
// I have tried both of the following lines
//SampleAssembly = Assembly.Load("FileInfoManager,Version=1.0.0.0");
SampleAssembly = ad.Load("FileInfoManager,Version=1.0.0.0");
//unload the dll
AppDomain.Unload(ad);
ad = null;
SampleAssembly = null;
string oldDLL = System.Windows.Forms.Application.StartupPath +
"\\FileInfoManager.dll";
string newDLL = System.Windows.Forms.Application.StartupPath +
"\\FileInfoManager2.dll";
try
{
File.Delete(oldDLL);
}
catch(Exception exc)
{
log.WriteEntry("Exception deleting file " + oldDLL + " : " +
exc.Message,System.Diagnostics.EventLogEntryType.Error);
}
File.Copy(newDLL,oldDLL,true);
File.Delete(newDLL);