how to delete the pluginassembly after AppDomain.Unload(domain)
Posted
by Ase
on Stack Overflow
See other posts from Stack Overflow
or by Ase
Published on 2009-01-08T17:10:37Z
Indexed on
2010/03/19
5:41 UTC
Read the original article
Hit count: 147
hello,
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
© Stack Overflow or respective owner