System.IO.FileLoadException:无法加载文件或程序集Log4net [英] System.IO.FileLoadException: Could not load file or assembly Log4net

查看:1116
本文介绍了System.IO.FileLoadException:无法加载文件或程序集Log4net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解决方案中添加了一个现有项目.当我使用MSTest运行程序运行所有单元测试时,在一些测试中出现以下错误:

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:

消息:测试方法soandso引发了异常: System.IO.FileLoadException:无法加载文件或程序集"log4net,版本1.2.12.0,Culture = neutral,PublicKeyToken = 669e0ddf0bb1aa2a"或其依赖项之一.找到的程序集的清单定义与程序集引用不匹配. (来自HRESULT:0x80131040的异常)

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)

我知道其他人也有相同的问题,并且关于此主题还有其他问题和解答.但是我尝试了很多事情,但是没有任何帮助. 我们使用的log4net版本是1.2.13.0.

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.

我用FUSLOGVW.exe检查了绑定错误. log4net会显示添加的程序集和一些未知程序集. 程序集中的log4net参考显示版本1.2.13.0,该版本是与NuGet一起添加的.因此,可能是一个依赖的程序集引起了所有这些麻烦. 我尝试将log4net更改回1.2.12.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.

当我使用MSTest testrunner运行所有测试时,会显示这些错误.当我仅运行失败的测试时,它们会通过.当我单独运行它们时,它们也会通过. 我尝试了绑定重定向,但是我是针对被测试的程序集而不是测试程序集进行的.我不知道如何为测试程序集执行此操作-没有配置. 当我使用Resharper测试运行程序运行测试时,它们也通过了(但是其他测试失败了). TFS Build服务器运行MSTest-runner,因此我需要使其与MSTest一起使用.

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?

推荐答案

找到了罪魁祸首.就像我怀疑的那样,一个依赖程序集引用了log4net 1.2.12.0.用于查找的工具是dotPeek.幸运的是,我们确实有相关程序集的源代码,我们可以对其进行更改以引用最新的log4net.这样就解决了这个问题.

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.

因此,如果有人遇到类似的问题,请使用dotPeek或类似的工具浏览相关程序集,以查找其引用的程序集版本.

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.

这篇关于System.IO.FileLoadException:无法加载文件或程序集Log4net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆