In our build process we have a process that takes the NUnit tests results xml
file and saves them to a database to use in our reports later
on.     This process has been working seamlessly
for about 10 months.  Then suddenly when we tried to add in one of
our old projects the process stopped working for this new project with a
invalid date format error 

Now using the normal troubleshooting techniques of understanding what has
changed and starting from there,   I started to investigate the new
project that we added.   After quick look I was able to narrow it down
to one test dll.    This test dll looked exactly the
same as the other test dll projects so that didn’t help.   So it
was down to the painful task of trial and error.  The first thing I did
was comment out all the tests and just left the [TestFixture] attribute
around the class.   Suddenly the date format was correct.  
So it must have been in the tests.   I carefully examined all the
tests and suddenly found the offending line.

 Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

Somebody had added in this line to the test which changes the culture
information of the current thread to the US which as I live in Australia effects
any date information that is outputted.   I grabbed a colleague
for a second set of eyes and we carefully examined the test to see if
there was any reason why this line needed to be there.   Both of us
decided it didn’t need to be there, so we removed the line, ran the test, green
lights all the way, date format right!  

The moral to this story is that when you are having problems with dates look
out for CultureInfo and the regional settings on your machine!!! 

Advertisements