I have three projects in my solution:
- A WCF web service which provides functionality I want to test
- A Web Application which calls that web service
- A test project which runs tests on the service.
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)]
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.
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).
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?
Update: I removed all references to log4net and the tests ran and succeeded without a problem. Obviously, this is far from preferable. Any suggestions?
Update 2: Some combination of these two things fixed the problem:
- Added a reference to log4net in my test project, making sure to initialise it completely.
- Used the release build of log4net 1.2.10 rather than the debug build.