Add-BindingRedirect doesn't seem to be working

Jun 24, 2011 at 1:51 PM


When I add the package Ninject.MockingKernel.Moq to one of my assemblies, and try to run a unit-test, I have this error:

System.IO.FileLoadException: Could not load file or assembly 'Moq, Version=4.0.812.4, 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)

After checking the version of the Moq package, I can see it is: 4.0.10827.0

I typed Add-BindingRedirect in the Package Manager Console, but nothing gets added to the App.config file, and I always get the exception, even when I add manually the missing infos.

Any thoughts?


Jun 24, 2011 at 3:19 PM

Are you running Add-BindingRedirect on the right project?

Jun 24, 2011 at 3:21 PM

Yes, I have only one test projet

Jun 24, 2011 at 6:19 PM

I think the problem is that when running unit test, you need to have the binding redirects affect the unit test executable. e.g. if using nunit.exe, you'd need to have an nunit.exe.config with the redirect. Unfortunately, this is not something that NuGet can easily do automatically, since it can't know what unit testing executable is being used. Kind of a bummer admittedly. Only solution I can think of is to have NuGet un-sign assemblies, which was discussed before.