Moq4: Conflicting references to Castle.Core

Created on 2 Oct 2017  路  1Comment  路  Source: moq/moq4

I'm experiencing the following warning while building my test projects:

Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.

I'm using moq version 4.7.127 (net462) and I have a reference to Castle.Core 4.2.0 (net462) via NuGet.

When enabling the detailed verbosity log level I find the following message in the log:

5>  There was a conflict between "Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc" and "Castle.Core, Version=4.1.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc".
5>      "Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc" was chosen because it was primary and "Castle.Core, Version=4.1.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc" was not.
5>      References which depend on "Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc" [C:\TFS\SIL_GIT\Aranea\v2\Main\packages\Castle.Core.4.2.0\lib\net45\Castle.Core.dll].
5>          C:\TFS\SIL_GIT\Aranea\v2\Main\packages\Castle.Core.4.2.0\lib\net45\Castle.Core.dll
5>            Project file item includes which caused reference "C:\TFS\SIL_GIT\Aranea\v2\Main\packages\Castle.Core.4.2.0\lib\net45\Castle.Core.dll".
5>              Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL
5>      References which depend on "Castle.Core, Version=4.1.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc" [].
5>          C:\TFS\SIL_GIT\Aranea\v2\Main\packages\Moq.4.7.127\lib\net45\Moq.dll
5>            Project file item includes which caused reference "C:\TFS\SIL_GIT\Aranea\v2\Main\packages\Moq.4.7.127\lib\net45\Moq.dll".
5>              Moq, Version=4.7.127.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL
5>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1987,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.

If I read this correctly, the package Castle.Core.4.2.0 is depending on Castle.Core, Version=4.0.0.0 and the package Moq.4.7.127 is depending on Castle.Core, Version=4.1.1.0 and the compile can not resolve the right version.

I added an assembly binding redirect but that didn't seem to make any difference.

 <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Unit tests that are using Moq classes fail with the following message:

Message: Initialization method Aranea.Core.UnitTests.ServicesTests.HelpServiceTests.Init threw exception. System.TypeInitializationException: The type initializer for 'Moq.Proxy.CastleProxyFactory' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'Castle.Core, Version=4.2.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) ---> System.IO.FileLoadException: Could not load file or assembly 'Castle.Core, Version=4.1.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).

Any ideas?

duplicate

Most helpful comment

Very briefly, the binding redirect should be:

<bindingRedirect oldVersion="0.0.0.0-4.999.999.999" newVersion="4.0.0.0" />
                                     ^^^^^^^^^^^^^              ^^^^^^^

Please see #461 for details, which is where we are tracking this versioning issue.

(This is a tooling-related problem. VS shouldn't suggest to you to update Castle.Core if you don't use it directly, and it often gets the redirects wrong. We have updated Moq to the latest Castle Core to mitigate this, unfortunately we can't release it due to a totally unrelated issue with our CI server. See the issue linked above for details.)

>All comments

Very briefly, the binding redirect should be:

<bindingRedirect oldVersion="0.0.0.0-4.999.999.999" newVersion="4.0.0.0" />
                                     ^^^^^^^^^^^^^              ^^^^^^^

Please see #461 for details, which is where we are tracking this versioning issue.

(This is a tooling-related problem. VS shouldn't suggest to you to update Castle.Core if you don't use it directly, and it often gets the redirects wrong. We have updated Moq to the latest Castle Core to mitigate this, unfortunately we can't release it due to a totally unrelated issue with our CI server. See the issue linked above for details.)

Was this page helpful?
0 / 5 - 0 ratings