log4net是否正在杀死我的WCF单元测试? [英] Is log4net killing my WCF unit tests?

查看:94
本文介绍了log4net是否正在杀死我的WCF单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的解决方案中有三个项目:

I have three projects in my solution:

  • 提供我要测试的功能的WCF Web服务
  • 调用该Web服务的Web应用程序
  • 在服务上运行测试的测试项目.

Web服务和Web应用程序都将log4net与单独的配置文件一起使用,而AssemblyInfo.cs中的这一行用于配置:

The web service and the web application both use log4net with separate configuration files and this line in the AssemblyInfo.cs for configuration:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

当我浏览到Web服务的URL时( http://localhost/MyWebService/MyWebService.svc ),它按预期显示-信息和指向wsdl的链接.

When I browse to the URL of the web service (http://localhost/MyWebService/MyWebService.svc), It appears as expected - information and a link to the wsdl.

当我使用Web应用程序时,它们都可以正常工作.该代码调用Web服务并获得正确的回复.从Web应用程序和Web服务都进行日志记录.

When I use the web application, it all works correctly. The code calls the web service and gets correct responses in reply. Logging occurs from both the web app and the web service.

但是,当我运行单元测试时,它们都因以下异常而失败:

However, when I run my unit tests, they all fail with the following exception:

Test method MyServiceTest.MyServiceAuthTest.TestValidateCorrectly threw exception: System.ServiceModel.ServiceActivationException: The requested service, 'http://localhost/MyWebService/MyWebService.svc' could not be activated. See the server's diagnostic trace logs for more information.

在我的本地计算机的事件日志中,我收到以下消息:

In the Event logs for my local machine, I get the following message:

WebHost failed to process a request. Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/12905972 Exception: System.ServiceModel.ServiceActivationException: The service '/MyWebService/MyWebService.svc' cannot be activated due to an exception during compilation. The exception message is: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045).

WebHost failed to process a request. Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/12905972 Exception: System.ServiceModel.ServiceActivationException: The service '/MyWebService/MyWebService.svc' cannot be activated due to an exception during compilation. The exception message is: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045).

我已经删除并替换了引用,进行了清理和重建,甚至清除了临时的asp.net文件,但都无济于事.该网站可以正常调用该服务,但是测试失败.

I've removed and replaced the references, cleaned and rebuilt, and even purged the temporary asp.net files, all to no avail. The web site calls the service with no problems, but the tests fail.

有人知道这里会发生什么吗?

Does anyone know what could be happening here?

更新:我删除了所有对log4net的引用,并且测试运行成功并且没有问题.显然,这远非可取.有什么建议吗?

Update: I removed all references to log4net and the tests ran and succeeded without a problem. Obviously, this is far from preferable. Any suggestions?

更新2 :这两件事的某种组合解决了该问题:

Update 2: Some combination of these two things fixed the problem:

  • 在我的测试项目中添加了对log4net的引用,请确保将其完全初始化.
  • 使用log4net 1.2.10的发行版而不是调试版.

推荐答案

您是否有单元测试对log4net库的引用?试试吧.

Do you have a reference from your unit test to the log4net library? Try it out.

其背后的原因:大多数单元测试框架在测试运行过程中将二进制文件隐藏在其他位置,但是通过这样做,它们并不能在所有情况下都找到深层嵌套的引用.我曾经与NHibernate和log4net相遇.如果使用MSTest,则无法禁用阴影. NUnit GUI为此提供了一个选项,但是我没有安装它,因此您必须自己寻找它:-)

The reason behind this: Most unit testing frameworks are shadowing the binaries to somewhere else during the test run, but by doing this they do not find deeply nested references in all cases. I once met this with NHibernate and log4net. In case of MSTest you cannot deactivate shadowing. NUnit GUI has an option for this, but I don't have it installed, so you have to look for it on your own :-)

这篇关于log4net是否正在杀死我的WCF单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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