System.IO.FileLoadException: Could not load file or assembly Log4net
Asked Answered
C

1

6

I added an existing project to my solution. When I run all unit tests with MSTest runner, I get the following error on a couple of tests:

Message: Test method soandso threw exception: System.IO.FileLoadException: Could not load file or assembly 'log4net, Version 1.2.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of it's dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT:0x80131040)

I know others have had the same problem and there is other questions and answers about this topic. But I tried many things, but nothing helped. The version of log4net we use is 1.2.13.0.

I checked with FUSLOGVW.exe for binding errors. The log4net shows up with the added assembly and some Unknown assembly. The reference of log4net in the assembly shows version 1.2.13.0 which was added with NuGet. So it is probably a dependent assembly that is causing all this trouble. I tried changing log4net back to version 1.2.12.0, but I still get the same error message.

When I run all the tests with MSTest testrunner, these errors show up. When I only run the failed tests, they pass. When I run them individually, they also pass. I tried binding redirection, but I did it for the assembly that is tested not the testing assembly. I did not know how to do that for a test assembly - there is no config. When I run the tests with Resharper test runner they also pass (but other tests fail). The TFS Build server runs the MSTest-runner, therefore I need to get it working with MSTest.

Does anyone know how I can get this resolved?

Cleliaclellan answered 31/3, 2014 at 18:52 Comment(3)
Try to investigate sample projects of log4netCobber
Delete the reference to log4net and add a new reference to the proper version of log4net, or change the Specific Version property of the reference to false.Rahmann
That was one of the first things I tried. I tried it with 1.2.13.0, 1.2.12.0 and with the log4net 1.2.13.0 with the old signature. The Specific Version property is set to false.Cleliaclellan
C
11

The culprit was found. Like I was suspecting, a dependent assembly was referencing log4net 1.2.12.0. The tool used to find out was dotPeek. Luckily we do have the source code for the dependent assembly and we can change it to reference the latest log4net. This solves this issue.

So if anyone has a similar problem, use dotPeek or a similar tool to go through the dependent assemblies to find out what versions of assemblies it is referencing.

Cleliaclellan answered 2/4, 2014 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.