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 ?
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With