简体   繁体   English

共享库的插件程序集

[英]plug-in assemblies sharing a library

My application includes a plug-in architecture, where DLLs, meeting certain criteria, placed in subdirectories of a well-known directory will be loaded into the application as needed. 我的应用程序包括一个插件体系结构,其中将满足特定条件的DLL(位于特定目录的子目录中)根据需要加载到应用程序中。

Plug-in assemblies are not always self-contained. 插件程序集并不总是独立的。 Some library DLLs are sometimes required. 有时需要某些库DLL。 These are placed next to each plug-in assembly. 这些放置在每个插件组合件旁边。 They don't meet the plug-in criteria, so they don't get loaded as plug-ins, but they get loaded by plug-ins. 它们不符合插件标准,因此它们不会作为插件加载,而是插件加载。

Sometimes, more than one plug-in uses the exact same version of the same library. 有时,多个插件使用的是同一库的完全相同的版本。 There is then a copy of the associated DLL in more than one plug-in directory. 然后在多个插件目录中有关联的DLL的副本。

This all works fine until someone decides that they don't need a certain plug-in and deletes its subdirectory. 除非有人决定不需要某个插件并删除其子目录,否则所有这些都可以正常工作。 The application detects this fine, so it won't try to use that plug-in any more. 该应用程序可以很好地检测到此情况,因此它将不再尝试使用该插件。 But, if that plug-in had a copy of a library DLL that is also used by another plug-in, one can experience exceptions. 但是,如果该插件具有一个库DLL的副本,而该副本也被另一个插件使用,则一个人可能会遇到异常。

I believe that this happens because .Net will only load that specific version of the library once per run of the application. 我相信发生这种情况是因为.Net每次运行该应用程序时只会加载该特定版本的库。 And the particular file that it loads it from is the one next to whichever plug-in happens to be used first. 它从中加载的特定文件是碰巧首先使用哪个插件的文件。 If that plug-in happens to be the one that's been deleted, then any other plug-ins using the same library will blow up, because they try to use the now-deleted DLL. 如果该插件恰好是被删除的插件,则使用同一库的任何其他插件都将被炸毁,因为它们尝试使用现已删除的DLL。

The plug-in assemblies are loaded using Assembly.LoadFrom(path). 使用Assembly.LoadFrom(path)加载插件程序集。 I don't think that I can use LoadFile(path), because that doesn't cope with references to other DLLs. 我不认为我可以使用LoadFile(path),因为那不能解决对其他DLL的引用。 And I can't use Load(typename), because what I have is the path, not the type name. 而且我不能使用Load(typename),因为我拥有的是路径,而不是类型名称。

Restarting the application fixes the problem, but that currently only happens "manually", after a failure. 重新启动应用程序可以解决该问题,但是当前只能在失败后“手动”发生。

Does anyone have a suggestion either for: - 是否有人针对以下方面提出建议?

  • Recovering from the problem, for instance by persuading .Net to change where it looks for that DLL 从问题中恢复,例如通过说服.Net更改查找该DLL的位置
  • Persuading the Web application containing the plug-in to re-start automatically in this situation 在这种情况下,说服包含该插件的Web应用程序自动重新启动
  • Rearchitecting to avoid the problem (but this is a mature in-use application, so my options are limited) 重新配置以避免该问题(但这是一个成熟的使用中的应用程序,因此我的选择受到限制)

Easy way is to go with an xml identifying the plugins, common references and their dependencies. 简单的方法是使用XML来识别插件,通用引用及其依赖项。 Common references section will have all dlls that other plug-ins are depend upon and are placed in separate folder. “公共引用”部分将包含其他插件依赖的所有dll,并将它们放置在单独的文件夹中。 Something like below should work for you: 像下面这样的东西应该为您工作:

<CommonReferences>
   <Dll id="" path="" version=""/>
   <Dll id="" path="" version=""/>
</CommonReferences>
<Plugins>
   <Plugin id="" path="" version="">
     <Dependencies>
         <DependencyDll id="" path="" version=""/>
         <DependencyDll id="" path="" version=""/>
         <DependencyDll id="" path="" version=""/>
     </Dependencies>
   </Plugin>
</Plugins>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM