Reputation: 4369
I installed Autofixture and Moq using Nuget.So I have moq version 4.
When running the following code
var fixture = new Fixture().Customize(new AutoMoqCustomization());
fixture.CreateAnonymous<ISomething>();
the following error shows up
System.IO.FileLoadException : Could not load file or assembly 'Moq, Version=3.1.416.3, Culture=neutral, PublicKeyToken=69f491c39445e920'
I've also tried redirected it to the v4,but with no luck.
<configuration>
<runtime>
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral"/>
<bindingRedirect oldVersion="3.1.416.3" newVersion="4.0.10827.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
What could be the problem here ?
Upvotes: 13
Views: 2559
Reputation: 17350
Accepted answer did not work for me since I want to use Moq 4 from the same class library (non exe) as AutoFixture.AutoMoq. There also seem to be no plans to support Moq 4 from the AutoFixture. I ended up using AutoFixture.AutoRhinoMocks as the next most popular choice, which does not conflict with Moq 4.
Upvotes: 1
Reputation: 59923
In order to redirect an assembly binding in a configuration file, you need to specify the urn:schemas-microsoft-com:asm.v1
namespace in the <assemblyBinding> element, like in this example:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Moq"
publicKeyToken="69f491c39445e920"
culture="neutral"/>
<bindingRedirect oldVersion="3.1.416.3"
newVersion="4.0.10827.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
It's interesting to point out that library assemblies compiled with an earlier version of .NET (such as Moq 3 and AutoFixture 2.1) will automatically be loaded in a process running on .NET 4.0 because of In-Process Side-by-Side execution. Here's a quote from MSDN about this:
If an application is compiled using the .NET Framework 4 runtime but includes a library that was built using an earlier runtime, that library will use the .NET Framework 4 runtime as well. However, if you have an application that was built using an earlier runtime and a library that was built using the .NET Framework 4, you must force your application to also use the .NET Framework 4
Related resources:
Upvotes: 18