"Could not load file or assembly Polly" error after installing CMP connector


Description

Sitecore Content Marketing Platform (CMP) connector installed on top of Sitecore XP instance might not be compatible with other installed modules, for example, Salesforce Marketing Cloud Connector (SFMC Connect) or Sitecore Publishing Service (SPS), because they are using different versions of Polly.dll. For example, SPS uses the Polly.dll 5.9.0 release, which does not have a publicKeyToken, and CMP uses Polly.dll 6.0.1 release with the publicKeyToken (c8a3ffc3f8f825cc). As a result, assembly binding redirects fail with the following error:

ERROR [Sitecore Connect for Sitecore CMP]: Message handler encountered an exception Sitecore.Exceptions.ConfigurationException: Could not create object from service provider . Config XML: <processor type="Sitecore.Connector.CMP.Pipelines.ImportEntity.FetchEntity, Sitecore.Connector.CMP" resolve="true" /> ---> System.IO.FileLoadException: Could not load file or assembly 'Polly, Version=6.0.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at Stylelabs.M.Sdk.WebClient.Http.InternalClient..ctor(Uri serviceEndpoint)
   at Stylelabs.M.Sdk.WebClient.Http.InternalClient..ctor(Uri serviceEndpoint, String clientId, String clientSecret)
   at Stylelabs.M.Sdk.WebClient.Http.InternalClient..ctor(Uri serviceEndpoint, String clientId, String clientSecret, String username, String password)
...

Solution

To resolve the issue, consider the following workaround:

  1. Keep Polly.dll 5.9 in the \bin directory of your site.
  2. Create a new folder, for example, cmp in your \bin folder.
  3. Copy the Polly.dll 6.0.1 assembly, that is supplied with CMP connector to the \bin\cmp folder.
  4. Add the following to the assemblyBinding node in the Web.config file:
    <dependentAssembly>
      <assemblyIdentity name="Polly" publicKeyToken="c8a3ffc3f8f825cc" />
      <codeBase version="6.0.0.0" href="bin\cmp\Polly.dll" />
      <codeBase version="6.0.1.0" href="bin\cmp\Polly.dll" />
    </dependentAssembly>