使插件文件夹在 ASP.NET 中可写
我在基于插件的 ASP.NET 应用程序中使用 MEF
。将文件系统观察器
与Container.Refresh()
连接起来,任何新插件都会在复制到插件文件夹后自动加载。
问题是当我想删除或替换已加载的插件时。它被w3wp
锁定,无法删除。我读过有关Shadow Copy
的内容,但找不到好的示例或文章。
I'm using MEF
in a plugin based ASP.NET application. Wiring up a File System Watcher
with Container.Refresh()
any new plugin is loaded automatically upon being copied to the plugin folder.
The problem is when I want to delete or replace a loaded plugin. It is locked by w3wp
and cannot be deleted. I read about Shadow Copy
but cannot find a good example or article.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将插件文件夹添加到 AppDomainSetup.ShadowCopyDirectories。此属性是一个以分号分隔的目录列表,其中包含应通过卷影副本加载的程序集。
通常,您还需要将 AppDomainSetup.ShadowCopyFiles 设置为 < code>"true" 但我认为这已经是 ASP.NET 应用程序域的默认设置。
但是,请注意,加载新版本的插件不会神奇地卸载旧版本。唯一的方法是卸载包含它的 AppDomain。由于这需要您在单独的应用程序域中加载插件,因此这可能会带来更多麻烦。
停止服务、更新 DLL,然后重新启动可能更简单、更安全、更有效。
Try adding the plugin folder to AppDomainSetup.ShadowCopyDirectories. This property is a semicolon-seperated list of directories containing assemblies that should be loaded via shadow copies.
Normally you also need to set AppDomainSetup.ShadowCopyFiles to
"true"
but I think this is already the default for ASP.NET appdomains.However, be aware that loading a new version of a plugin will not magically unload the old version. The only way to do that is to unload the AppDomain containing it. Since this requires you to load plugins in a separate appdomain, this is probably more trouble than it is worth.
It is probably simpler, safer and more effective to just stop the service, update the DLLs, and restart.
确保正确清理所有非托管资源。听起来您可能已经打开了一个文件流,但没有正确关闭/处置它,这可能会通过首先使用该文件的进程锁定该文件。有关
using
语句的更多信息:http://www.blackwasp.co .uk/UsingStatement.aspxMake sure you are cleaning up all your unmanaged resources properly. It sounds like you may have opened a file stream but didn't properly close/dispose of it, and this may lock up a file by the process that was working with it in the first place. More info on
using
statement here: http://www.blackwasp.co.uk/UsingStatement.aspx