Assembly Class Locking Issue
-
I am using the Assembly.LoadFrom() method in my application to extract some information from some DLLs and I am running into a locking problem. Even after I am done with the file and have set the Assembly to null it keeps the file I loaded locked until the application terminates. The problem comes when I try and update the DLL with a new version automatically via the main application. I am unable to copy the newly downloaded version over because the file still reports as locked by Windows. Does anyone know a way to tell the Assembly object to release it's hold on the file it loaded?
-
I am using the Assembly.LoadFrom() method in my application to extract some information from some DLLs and I am running into a locking problem. Even after I am done with the file and have set the Assembly to null it keeps the file I loaded locked until the application terminates. The problem comes when I try and update the DLL with a new version automatically via the main application. I am unable to copy the newly downloaded version over because the file still reports as locked by Windows. Does anyone know a way to tell the Assembly object to release it's hold on the file it loaded?
An assembly cannot be unloaded from an
AppDomain
. In order to make sure the file doesn't remained locked in use, however, you can read-in the file, grab the raw bytes, and load the buffer:byte[] assembly;
using (FileStream fs = new FileStream(pathToAssembly, FileMode.Open,
FileAccess.Read, FileShare.Read))
assembly = new byte[fs.Length];
fs.Read(assembly, 0, assembly.Length);
fs.Close();
}
AppDomain.CurrentDomain.Load(assembly, null);Microsoft MVP, Visual C# My Articles
-
An assembly cannot be unloaded from an
AppDomain
. In order to make sure the file doesn't remained locked in use, however, you can read-in the file, grab the raw bytes, and load the buffer:byte[] assembly;
using (FileStream fs = new FileStream(pathToAssembly, FileMode.Open,
FileAccess.Read, FileShare.Read))
assembly = new byte[fs.Length];
fs.Read(assembly, 0, assembly.Length);
fs.Close();
}
AppDomain.CurrentDomain.Load(assembly, null);Microsoft MVP, Visual C# My Articles
Thanks, that method works great.