【发布时间】:2009-10-22 05:39:50
【问题描述】:
我的解决方案中有三个项目:
- 提供我想要测试的功能的 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 的发布版本而不是调试版本。
【问题讨论】:
标签: c# wcf unit-testing log4net