Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 805
Amir Popovich Avatar asked Oct 19 '22 08:10

Amir Popovich


1 Answers

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.

like image 194
Mike Barry Avatar answered Oct 26 '22 22:10

Mike Barry