更改加载了MEF的Dll [英] Change Dll loaded with MEF

查看:89
本文介绍了更改加载了MEF的Dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MEF和System.ComponentModel.Composition.dll加载一些dll.

I'm using MEF and the System.ComponentModel.Composition.dll to load some dll.

我正在做类似的事情:

AggregateCatalog catalog = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly()), new DirectoryCatalog(directory));
_container = new CompositionContainer(catalog);
_container.ComposeParts(this);

导入我的dll.

一段时间后,我想更新我的dll,但如果尝试删除它,则访问被拒绝,因为程序确实使用了它.

After some times, I would like to update my dll but if I try to delete it, I have an access denied, because it's alrealdy used by the program.

如何释放dll,替换为新的dll并再次加载dll? (无需关闭程序)

How can I release the dll, replace with a new dll and load the dll again ? (without closing the program)

预先感谢您的帮助

推荐答案

您需要在AppDomain中启用卷影复制,这将迫使应用程序的行为类似于未从源位置运行可执行内容的Web应用程序,只是一个临时位置.

You need to enable shadow copying in the AppDomain, this forces the application to behave similarly to a web app where the executable content is not running from the source location, but a temporary location.

您唯一的问题是

  1. 使用过时的方法AppDomain.CurrentDomain.SetShadowCopyFiles()将其强制在当前域上.不建议这样做,因为它已不赞成使用:
  2. 在创建 AppDomain时使用AppDomainSetup.ShadowCopyFiles = "true";.然后,您需要在另一个AppDomain中推迟执行程序集. 表单帖子可能有帮助?
  1. Use an obselete method AppDomain.CurrentDomain.SetShadowCopyFiles() which forces it on the the current domain. Not advisable as this has been deprecated in favour of:
  2. Use AppDomainSetup.ShadowCopyFiles = "true"; when creating a new AppDomain. You then need to defer execution of the your assembly in the other AppDomain. Maybe this form post can help?

我不确定您是否可以通过应用程序配置启用卷影复制...

I'm not sure you can enable Shadow Copying through application configuration...

这篇关于更改加载了MEF的Dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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