如何在AppDomain.Unload(domain)之后删除pluginassembly [英] how to delete the pluginassembly after AppDomain.Unload(domain)

查看:114
本文介绍了如何在AppDomain.Unload(domain)之后删除pluginassembly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题. 我想删除一个已经加载的程序集(硬盘上的plugin.dll),但是该程序集已被操作系统(vista)锁定,即使我已经卸载了该程序集.

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");

我还需要assemblyinfos,因为我不知道pluginassembly中的哪些类实现了IPlugin接口.一个插件组合中应该有多个插件.

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);

如何在不锁定程序集的情况下从appDomain获取assemblyinfos?

How is it possible to get the assemblyinfos from the appDomain without locking the assembly?

最诚挚的问候

推荐答案

我想我已经回答了! 如果您想删除已加载的程序集,则ØyvindSkaar的答案将不起作用.

I think i've the answer! the answer from Øyvind Skaar will not work, if you would like to delete the loaded assembly.

代替

using (FileStream dll = File.OpenRead(path))
{
   fileContent = new byte[dll.Length];
   dll.Read(fileContent, 0, (int)dll.Length);
}
Assembly assembly = appDomain.Load(fileContent);

您必须使用

byte[] b = File.ReadAllBytes(assemblyName);
assembly = Assembly.Load(b);

最诚挚的问候

这篇关于如何在AppDomain.Unload(domain)之后删除pluginassembly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆