Figuring out what assembly is trying to load a specific (missing) DLL version in .NET

If you ‘re running into an error similar to this one:

The type initializer for 'YourNamespace.Program' threw an exception.
---> System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=, Culture=neutral, PublicKeyToken=8774c74090335470' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at YourNamespace.Program..cctor()
   --- End of inner exception stack trace ---
   at YourNamespace.Program.Main()

Then post is for you!

What’s happening here is that Program is referencing a log4net dll version But another, currently unidentified, DLL that Program is referencing is looking for version .

There are two ways of fixing this.

  1. Adding an assembly redirect in the app.config or web.config
  2. Recompiling the unidentified DLL with log4net version

In this post I’ll focus on the recompiling approach. The first thing we need to do is identify the unidentified DLL we talked about above. To do this:

  1. Open the “Developer Command Prompt for VS2015” as an administrator.
    • Not sure if you really need to be an admin; doing it just in case.
  2. Type “fuslogvw” and hit enter
  3. Click the Settings button
  4. Select “Log bind failures to disk” and click OK
  5. Click the “Delete All” button
  6. Make your dll error happen again
  7. Click the Refresh button on fuslogvw
  8. You should see the dll binding failure displayed on the report
  9. Double click the failure.
  10. The report is an HTM file that you can open with your preferred web browser.
  11. This report will tell us the name of the unidentified DLL
  12. You can now recompile the now identified DLL with the same DLL version that your main Program is referencing.
    • If the identified DLL does not belong to you, meaning you can’t recompile it, you need to add an assembly redirect on your app.config or web.config.