我的解决方案中有三个项目:
-
提供我要测试的功能的WCF Web服务
-
调用该Web服务的Web应用程序
-
对服务运行测试的测试项目。
Web服务和Web应用程序都使用带有单独配置文件的log4net,而assemblyinfo.cs中的这一行用于配置:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
当我浏览到Web服务的URL时(
http://localhost/MyWebService/MyWebService.svc
,它将按预期显示-信息和到WSDL的链接。
当我使用Web应用程序时,它都正常工作。代码调用Web服务并得到正确的响应。日志记录同时从Web应用程序和Web服务中进行。
但是,当我运行单元测试时,它们都会失败,并出现以下异常:
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.
在本地计算机的事件日志中,我收到以下消息:
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文件,但都无济于事。网站调用服务没有问题,但测试失败。
有人知道这里会发生什么吗?
更新
:我删除了对log4net的所有引用,测试运行成功,没有出现问题。显然,这远不是更好的选择。有什么建议吗?
更新2
:这两件事的结合解决了问题:
-
在我的测试项目中添加了对log4net的引用,确保它完全初始化。
-
使用了log4net 1.2.10的发布版本,而不是调试版本。