12 มกราคม 2555 14:34
We've developed an C 4.0# application where we have a WCF web service that uses MEF to bind to series of plugin components. Depending on the service that is required of the service - a specific plugin in used. These plugins are stored in a shared area and are downloaded to the webservice as and when required. The plugins are regularly changed and rebuilt (for bug fixes, or other enhancements).
One of the triggers for the web service to download, is because an administrator sees that a library has been updated because a bug has been fixed. The application provides a UI for the administrator to download a plugin from shared area, to the web service local disk, so that it can be accessed when required quickly by the service application. Both the plugin and service use a common set of dependent libraries.
When a plugin in updated (normally the version number for the plugin assembly changes as may the version number of one or more of its assembly dependencies) we often get this exception the next time the web service tries to load the updated plugin:
Message: Could not load file or assembly 'BankPlugin, Version=2012.1.12.32, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
The error occurs when the call to the ComposeParts method is made (see example code below). It occurs we think because an assembly with a specific version number is not found.
_directoryCatalog = new DirectoryCatalog(GetAssemblyPath(pluginLocation, _pluginStorage)); catalog.Catalogs.Add(_directoryCatalog); //Create the CompositionContainer with the parts in the catalog _container = new CompositionContainer(catalog); //Fill the imports of this object _container.ComposeParts(this);
The reason for this i think it because one of the dependency assembly version numbers has changed after a plugin update. This dependent assembly is required to be copied to the webservice as well, so that the plugin and the webservice are using the same version of the assembly. What we do when this occurs, is to rebuild the web service code so that the web service assemblies are correctly bound to the updated version of the plugin dependency. We then update all webservice assemblies that are running on the production site.
This is quite a disruptive process, which means that whenever any plugin is updated, we in effect have to rebuild all other plugins and web service code. We then have to update the webservice code and restart the service.
Is there a way we can avoid the process? it seems that when using MEF, in effect assemblies are still bound to each other anyway (which defeats the whole purpose of the framework).
What's the best practice way of updating common dependencies used by both the plugin and the main application?
- แก้ไขโดย ossent 12 มกราคม 2555 14:38