‘NUnit has stopped working’ message after crash

My PC crashed recently and after reboot NUnit refused to launch. It crashed when double clicking the icon with the generic Windows error ‘ has stopped working’. The message also tells you that Windows is trying to find a reason but then just exits. I obviously tried rebooting, uninstalling/reinstalling etc.

If this happens, try to launch NUnit from the command window – the default location of the executable is C:\Program Files (x86)\NUnit 2.6.1\bin\nunit-console.exe. The same error message will appear, but now on the command window you should see a stack trace that might help. For me, it told me that NUnit was trying to load a ‘settings’ file but couldn’t. Unfortunately it didn’t say where that file was. In this case, try to use the Debug button on the error message to launch Visual Studio. If this brings up the exception (it doesn’t always seem to – you may have to try a few times) then click on View Detail on the Exception window to find the details of the exception. I found my answer in the InnerException->SourceUri property, and so possibly you will too!

For me, I found that it was trying to load a file called NUnitSettings.xml, from my AppData\Local\NUnit directory. This file must have become corrupted when my PC crashed, as it was empty. NUnit was moaning about this. I simply deleted the file and voila, I was back up and running with NUnit again.

Advertisements

Generate a string array from a list of objects

This is quite a neat method of generating a string array from a list of objects using LINQ. Just thought I’d blog as I’d not really used the Select method before and it is pretty useful.

The example uses an MVC SelectList, but would work for any List type, where blah is an object.

string[] myArray = MySelectList.Select(x => x.Value).ToArray();