Is log4net killing my WCF unit tests?

I have three projects in my solution:

  • A WCF Web Service providing the functionality I want to test.
  • The web application that calls this web service
  • Test project that runs tests on a service.

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

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

      

When I view the web service url ( http: //localhost/MyWebService/MyWebService.svc ) it looks as expected - information and link to the WSDL.

When I use the web app everything works correctly. The code calls the web service and gets the correct responses in return. Logging occurs from both the web application 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 diagnostic trace logs for more information.

The following message appears in the event logs for my local computer:

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 removed and replaced links, cleaned and rebuilt, and even cleaned up the temporary asp.net files, all to no avail. The website calls the service without issue, but the tests fail.

Does anyone know what might be going on here?

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

Update 2 . Some combination of the two fixed the problem:

  • Added a link to log4net in my test project, making sure it is fully initialized.
  • The build used is the log4net 1.2.10 release build, not the debug build.
+2


source to share


2 answers


Do you have a link from the unit test to the log4net library? Try it.



Reason for this: Most unit test units hide binaries elsewhere during test run, but they do not find deeply nested references in all cases. I've met this once with NHibernate and log4net. In the case of MSTest, you cannot turn off shading. The NUnit GUI has an option to do this, but I don't have one, so you have to search for it yourself :-)

+3


source


I would also consider adding log4net handling to the unit test configuration. This is very helpful when dealing with failures anyway.
This link explains it for NUNit and it should be possible for other frameworks as well.



0


source







All Articles