Question

I have an application that can run several plugins dynamically. After installing the application, the user just drops the appropriate plugin into the installation directory, and the program will dynamically load them based on an interface.

The problem I am running into is that the plugins reference a library in the main application to access the correct interface and to share global settings. I want to be able to add plugins at any time without the user needing to reinstall. However, since the plugin references a library, when I try to load them, I am getting the error:

Could not load file or assembly 'program', Version=0.1.0.24838, Culture=neutral, PublicKeyToken=623917...' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I know I can avoid this error if I add all plugins to the installer, but if I later add a new plugin, the user will have to uninstall and reinstall. The reason for loading the plugins dynamically was so the user could just drop a new one in, and it would work.

Is there a way for a plugin to reference objects in the main application without worrying about the version of the application?

Thanks.

Était-ce utile?

La solution

You can use runtime binding redirect for the assemblies which are changed, if change is only in plugin assembly version.

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="myAssembly"
                              publicKeyToken="32ab4ba45e0a69a1"
                              culture="neutral" />
            <bindingRedirect oldVersion="1.0.0.0"
                             newVersion="2.0.0.0"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

You can provide updates via separate patch(zip file). (No need for install/uninstall).

Autres conseils

Common approach is to make special "public interface" assembly that have explicit version (that is only changed when interfaces change) and link both plugins and main app to that assembly. You still will need to provide backward compatibility for such assembly and use binding redirects (i.e. configured as shown in Tilak's +1 answer).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top