Tuesday 16 October 2007

NCover generates an unhandled exception

Recently whilst setting up a continuous integration environment using cruise control, I came across a problem when running NCover (Version 1.5.5) from NCoverExplorer. I entered all the usual information about profiling applications, etc... and it gave me an error.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
Server stack trace: at NUnit.Core.SimpleTestRunner.CountTestCases(ITestFilter filter) at NUnit.Core.DelegatingTestRunner.CountTestCases(ITestFilter filter) at NUnit.Core.DelegatingTestRunner.CountTestCases(ITestFilter filter) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at NUnit.Core.TestRunner.CountTestCases(ITestFilter filter) at NUnit.Util.ProxyTestRunner.CountTestCases(ITestFilter filter) at NUnit.Util.AggregatingTestRunner.CountTestCases(ITestFilter filter) at NUnit.Util.AggregatingTestRunner.Run(EventListener listener, ITestFilter filter) at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options) at NUnit.ConsoleRunner.ConsoleUi.Main(String[] args)

This had me baffled for hours. I am using Windows Server 2003 x64 Standard Edition, so I trotted off down a route of 'It has to be because I am using a 64bit windows OS'. After installing the new version of NCover (v2.0.2) which promised to work on a 64bit platform and a newer version of NUnit (2.4.2), it still did not work. I was at my whits end.

The solution was simple however.... My "application arguments" section in the NCoverExplorer NCover runner contained a path and file name to my NUnit configuration as it was not located in the default working folder. This path contained spaces and I did not enter it in quotes (I assumed the NCover Runner would be clever enough to do this for me). So, I put this in quotes and hey presto - success!

I hope this helps prevent someone else going through quite so much pain as I did!