title: Windows Service gives String was not recognized as a valid DateTime exception but the same code running properly in Console Application
body: <p>Windows Service gives String was not recognized as a valid DateTime exception but the same code running properly in Console Application</p>
  
  <pre><code>Object max = cmd.ExecuteScalar();   //max will have 6/30/2012 12:00:00 AM 
  DateTime currentDt = DateTime.Now;
  currentDt = DateTime.ParseExact(max.ToString(), "M/d/yyyy h:mm:ss tt", CultureInfo.CurrentCulture.DateTimeFormat);                         //This Line Gives Error in WindowsService Only
  StreamWriter sw = new StreamWriter("E:\\ram\\SampleService.txt", true);
  sw.WriteLine(currentDt.ToString());
  sw.Close();
  </code></pre>
  
  <p>I even Changed System DateTime Format Settings to Engish - Us Settings.ShortDatetime is M/d/yyyy and Longtime is h:mm:ss tt.</p>
  
  <p>Can someone help me resolve this issue? </p>