i have a weird problem. i would like to delete an assembly(plugin.dll on harddisk) which is already loaded, but the assembly is locked by the operating system (vista), even if i have unloaded it.
f.e.
AppDomainSetup setup = new AppDomainSetup();
setup.ShadowCopyFiles = "true";
AppDomain appDomain = AppDomain.CreateDomain(assemblyName + "_AppDomain", AppDomain.CurrentDomain.Evidence, setup);
IPlugin plugin = (IPlugin)appDomain.CreateInstanceFromAndUnwrap(assemblyName, "Plugin.MyPlugins");
I also need the assemblyinfos, because I don't know which classes in the pluginassembly implements the IPlugin Interface. It should be possible to have more than one Plugin in one Pluginassembly.
Assembly assembly = appDomain.Load(assemblyName);
if (assembly != null) {
Type[] assemblyTypes = assembly.GetTypes();
foreach (Type assemblyTyp in assemblyTypes) {
if (typeof(IPlugin).IsAssignableFrom(assemblyTyp)) {
IPlugin plugin = (IPlugin)Activator.CreateInstance(assemblyTyp);
plugin.AssemblyName = assemblyNameWithEx;
plugin.Host = this;
}
}
}
AppDomain.Unload(appDomain);
How is it possible to get the assemblyinfos from the appDomain without locking the assembly?
best regards
You can not unload an assembly from an appdomain. You can destroy appdomains, but once an assembly is loaded into an appdomain, it's there for the life of the appdomain.
The CurrentDomain property is used to obtain an AppDomain object that represents the current application domain. The FriendlyName property provides the name of the current application domain, which is then displayed at the command line.
I think i've the answer! the answer from Øyvind Skaar will not work, if you would like to delete the loaded assembly.
instead of
using (FileStream dll = File.OpenRead(path))
{
fileContent = new byte[dll.Length];
dll.Read(fileContent, 0, (int)dll.Length);
}
Assembly assembly = appDomain.Load(fileContent);
you have to use
byte[] b = File.ReadAllBytes(assemblyName);
assembly = Assembly.Load(b);
best regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With