2

I am having some problems with a single test project on our build server. Some of the tests in the project uses AutoFixture with AutoMoq.

Since AutoMoq uses an older Moq version than the one we use otherwise, we have a redirection in the app.config (made by the AutoMoq NuGet script I assume):

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.1409.1722" newVersion="4.2.1409.1722" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Ploeh.AutoFixture" publicKeyToken="b24654c590009d4f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.20.2.0" newVersion="3.20.2.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

The tests run without a problem on the developer machines, but one project (among many that uses AutoFixture, AutoMoq and Moq) throws this at me when run with TeamCitys NUnit runner:

Test(s) failed. System.IO.FileLoadException : Could not load file or assembly 'Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at Ploeh.AutoFixture.AutoMoq.MockPostprocessor.Create(Object request, ISpecimenContext context)
   at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
   at Ploeh.AutoFixture.CustomizationNode.Create(Object request, ISpecimenContext context)
   at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
   at Ploeh.AutoFixture.Kernel.TracingBuilder.Create(Object request, ISpecimenContext context)
   at Ploeh.AutoFixture.Kernel.TerminatingWithPathSpecimenBuilder.Create(Object request, ISpecimenContext context)
   at Ploeh.AutoFixture.BehaviorRoot.Create(Object request, ISpecimenContext context)
   at Ploeh.AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
   at Ploeh.AutoFixture.Fixture.Create(Object request, ISpecimenContext context)
   at Ploeh.AutoFixture.Kernel.SpecimenContext.Resolve(Object request)
   at Ploeh.AutoFixture.SpecimenFactory.Create[T](ISpecimenContext context, T seed)
   at Ploeh.AutoFixture.SpecimenFactory.Create[T](ISpecimenContext context)

Why is the Moq reference to (4.0.10827.0 apparently) not redirected to 4.2.1409.1722?

I have checked the build-server working directory and the app.config and dlls looks fine.

Holstebroe
  • 4,993
  • 4
  • 29
  • 45

2 Answers2

0

As explained in the relevant AutoFixture issue AutoFixture does not and will not depend on latest for the sake of it.

Your error message has nothing to do with any version demanded by any AutoFixture itself hence something in your environment is the only possible explanation. Id' be using \\live.sysinternals.com\tools\procexp.exe to see what's coming from where.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
  • Using procexp on a unit test run by a build server (it is a build server only problem) would probably be hard. I ended up rewriting the tests without AutoFixture instead. All other test projects that use AutoFixture andMoq works fine. – Holstebroe Oct 22 '14 at 11:29
  • 1
    My point is that a Moq `4.2.1409.1722` req is definitely NOT coming from AF and hence you need to find what in your environment introduces the conflict. It's not like there's a stray electron or something in AutoFixture causing this. It's going to be something pretty boring when you root cause it. While rewriting without dependencies always has its merits, so does root causing stuff and figuring out what you and/or your build scripts did wrong. – Ruben Bartelink Oct 22 '14 at 12:57
0

I don't know if this will help, but I had a problem with similar symptoms, and the solution turned out to be something else altogether, namely this: https://stackoverflow.com/a/3668371/487544

Community
  • 1
  • 1
Tim Iles
  • 2,232
  • 2
  • 24
  • 26