What's the recommended way to run plugins with dependency dll's that have different version?

纵然是瞬间 提交于 2019-12-07 06:02:43

问题


I have a WCF plugin service that loads plugins via MEF and runs them.

Each plugin is a directory with multiple dll's that implements a specific interface.

I load all the plugins in the same AppDomain using MEF (DirectoryCatalog) and run them in a generic way (using reflection).

Now lets assume I have two plugins with dll dependencies:

Plugin1
     ----> Entities 1.0.0.1

Plugin2
     ----> Entities 1.0.0.2

I've added some new entities in 1.0.0.2.

When I run the plugin's I get a sporadic error that the new entities doesn't exist in the dll.

I guess that the error occurs since I'm running the code in the same AppDomain and the first Entities.dll that loads is the one that will serve all my plugins.

So, how can I run each plugin with isolation, without creating a new appdomain?

Is there any way I can tell MEF to load all plugin dependencies somehow?

I've read about a couple of solutions on the web:

  1. Create a new appdomain for each plugin - I don't want to go there.

  2. Use the <dependentAssembly> - This didn't work when I first tried it and I don't want my plugin server to get updated on each assembly dependency version change. Plus, I want to be able to run plugins with different assembly versions.

  3. Sign the assemblies with a snk - I didn't try this yet and I'm not sure this solution will work. How will the framework know that he needs to load a different assembly? How is this different from assemblies with different versions? Will I need to configure my service somehow in order to make this work?

Does anybody have any better idea for me? What's the recommended way to run isolated plugins?


回答1:


You need to sign your assemblies And make sure the assembly version is different on each one. See the answer from the following: C# Load different versions of assembly to the same project

The CLR does support loading multiple versions of strongly named assemblies into the same AppDomain. This only works though if your assemblies are strongly named and each one has a different version than the other.



来源:https://stackoverflow.com/questions/37431249/whats-the-recommended-way-to-run-plugins-with-dependency-dlls-that-have-differ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!