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=126.96.36.199, 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 188.8.131.52. But another, currently unidentified, DLL that Program is referencing is looking for version 184.108.40.206 .
There are two ways of fixing this.
- Adding an assembly redirect in the app.config or web.config
- Recompiling the unidentified DLL with log4net version 220.127.116.11
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:
- 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.
- Type “fuslogvw” and hit enter
- Click the Settings button
- Select “Log bind failures to disk” and click OK
- Click the “Delete All” button
- Make your dll error happen again
- Click the Refresh button on fuslogvw
- You should see the dll binding failure displayed on the report
- Double click the failure.
- The report is an HTM file that you can open with your preferred web browser.
- This report will tell us the name of the unidentified DLL
- 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.