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

允我心安 提交于 2020-01-02 04:03:07

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/22769806/system-io-fileloadexception-could-not-load-file-or-assembly-log4net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!