System.IO.FileLoadException
HResult=0x80131040
Message=Could not load file or assembly … or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference.
This is a very common error in the Microsoft world and it has been causing me some grief for a while. The first thing to note is that the error is misleading in that it tells you what it found and this is confusing at best.
Microsoft actually have some good tools available to help with this but they don’t really advertise them very much. It took me some considerable time to discover this. In this particular case the tool is called fuslogvw.exe i.e. fusion log viewer. The page about it on the Microsoft site gives a rather simplistic overview and makes no mention of how to get it working correctly. Certainly for me it took a while and I’m still not entirely certain what I did but it does now seem to work for me. The most helpful site I found was StackOverflow.
This particular tool is part of the SDK, so you need that installed. In my case I fired up the developer console as an admin and ran the viewer. Unfortunately the viewer was completely empty whatever I did. So I looked around and discovered that there is a registry setting that you need. The value of Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\LogFailures needs to be 1. In my case that was already set. I also discovered that the version of the viewer might make a difference so I located the viewer in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin and ran that which seemed to work as expected. When I set the viewers Log Bind Failures to Disk on and refreshed, then it showed me some data.
The great irony in my case was that it showed that the stray file was in the bin folder, so I could just delete that and carry on. Of course that didn’t work, nor did clearing the nuget cache, changing the auto assembly binding settings etc etc.
Update
I’m still having issues with this in one particular legacy application. After much searching over a period of weeks, the most unusual solution came to light which seems to resolve this issue — I found this on StackOverflow, the suprisingly simple answer is to just delete the assembly binding redirect and for now that seems to be working.