Plugins with the same third-party assembly in different versions

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 years ago
Hi,
I have a simple question. Is it possible to have 2 differents plugins using the same third-party assembly in 2 different versions? For example: the "plugin A" with a.dll (version 1.0.0) and "plugin B" with a.dll (version 1.1.0) ?

Thanks
6 years ago
I am also interested to know if this is possible.
6 years ago
In general, probably not, but it depends...
First, typically new plugin versions come out to support new versions of nopCommerce, so both would have to be for the same version of nopCommerce.  (Although it's possible that a plugin could work in multiple versions of nopCommerce, it's been quite some time since that actually worked, because many dependent libraries, e.g. AutoFac, get upgraded and therefore plugins now usually need to be specific to be recompiled to the nopCommerce version.)

Sometimes you can run two copies of the same plugin, but it requires renaming one of the .dll files, and also changing its System Name in the Description.txt file.  However, if plugins have their own "settings", then both copies would reference the same set of settings (and language resource strings too).
6 years ago
I needed a newer version of a nuget package that was also used in nopCommerce and a third party plugin. And I found a workaround for my problem. I changed the code to compare full assembly name when checking if an assembly is already loaded and, I added in web.config a codeBase element for every AutoMapper version. This way the different version nuget package assembly is not skipped when loading assemblies and every assembly is loaded from the correct file path.

So the method IsAlreadyLoaded from PluginManager becomes:

private static bool IsAlreadyLoaded(FileInfo fileInfo)
{
    //compare full assembly name
    try
    {
        var fileAssemblyName = AssemblyName.GetAssemblyName(fileInfo.FullName);
        foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
        {
            if (a.FullName.Equals(fileAssemblyName.FullName, StringComparison.InvariantCultureIgnoreCase))
                return true;
        }
    }
    catch (Exception exc)
    {
        Debug.WriteLine("Cannot validate whether an assembly is already loaded. " + exc);
    }
    return false;

    //do not compare the full assembly name, just filename
    //try
    //{
    //    string fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileInfo.FullName);
    //    if (fileNameWithoutExt == null)
    //        throw new Exception(string.Format("Cannot get file extnension for {0}", fileInfo.Name));
    //    foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
    //    {
    //        string assemblyName = a.FullName.Split(new[] { ',' }).FirstOrDefault();
    //        if (fileNameWithoutExt.Equals(assemblyName, StringComparison.InvariantCultureIgnoreCase))
    //            return true;
    //    }
    //}
    //catch (Exception exc)
    //{
    //    Debug.WriteLine("Cannot validate whether an assembly is already loaded. " + exc);
    //}
    //return false;
}


And added this in web.config file from Nop.Web:

<dependentAssembly>
  <assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" />
  <codeBase version="6.1.1.0" href="Plugins\Integration.ServiceBus\AutoMapper.dll" />
  <codeBase version="4.1.1.0" href="bin\AutoMapper.dll" />
</dependentAssembly>


See issue 2523.
5 years ago
This problem can be resolved only by dll mapping in web.config.

CASE:
Suppose there are 2 plugins with the same dll used but with different version.

For instance,
Plugin A which is already installed and using Google.Apis.dll ver 1.13.0.0.
And when you install Plugin B which is using Google.Apis.dll ver 1.25.0.0.

Here It will cause the error Google.Apis.dll ver 1.25.0.0 not found when you try to configure Plugin B.

The solution for the above issue is

You can resolve this manually or by using code.

1.  Manually Update in web.config - Add the reference of updated assembly in the web.config to resolve the issue as I have mentioned below
                
    

      <dependentAssembly>
        <assemblyIdentity name="Google.Apis" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
        
        <codeBase version="1.25.0.0" href="Plugins\Nop.Plugin.Seurata.GoogleShopping\Google.Apis.dll" />
        
         <bindingRedirect oldVersion="0.0.0.0-1.25.0.0" newVersion="1.25.0.0" />
      </dependentAssembly>


2. Using Code - Follow these steps
        a. Write code in Plugin 2 to find the dependent dll in plugins/ folder.
        b. If the dlls are found then match the version. If the version is same then there will be no issue.
        c. In case the version is not matched then add the point no. 1 setting using the code in the web.config for your dependent dll. The higher version of dll must be mapped in the config.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.