System.IO.FileLoadException: Failed to load Log4net file or assembly

I added an existing project to the project. When I run all unit tests with the MSTest runner, I get the following error on several tests:

Message: the test method also raised an exception: System.IO.FileLoadException: Failed to load file or assembly 'log4net, Version 1.2.12.0, Culture = neutral, PublicKeyToken = 669e0ddf0bb1aa2a' or one of these dependencies. The located assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I know that others had the same problem, and there are other questions and answers on this topic. But I tried a lot, but nothing helped. The version of log4net we are using is 1.2.13.0.

I checked with FUSLOGVW.exe binding errors. Log4net appears with an added assembly and some unknown assembly. The log4net link in the assembly shows version 1.2.13.0, which was added using NuGet. So this is probably a dependent assembly that causes all these problems. I tried changing log4net to version 1.2.12.0, but I still get the same error message.

When I run all tests using the MSTest testrunner, these errors appear. When I only run unsuccessful tests, they pass. When I launch them individually, they also pass. I tried redirect redirection, but I did it for an assembly that was not tested on a test assembly. I did not know how to do this for a test build - there is no configuration. When I run tests using the Resharper test runner, they also pass (but other tests fail). The TFS Build server starts MSTest-runner, so I need to get it to work with MSTest.

Does anyone know how I can solve this?

+6
source share
1 answer

The defendant was found. As I suspected, the dependent assembly referred to log4net 1.2.12.0. The tool used to find out was dotPeek. Fortunately, we have the source code for the dependent assembly, and we can change it to reference the latest log4net. This solves this problem.

So, if someone has a similar problem, use dotPeek or a similar tool to go through the dependent assemblies to find out which version of the assembly it is referencing.

+10
source

All Articles