0

I'm configuring a new server and have been experiencing issues with parsing dates where the following code worked perfectly on the old server but not the new server.

IFormatProvider fpCanada = System.Globalization.CultureInfo.CreateSpecificCulture("en-CA");
Convert.ToDateTime(strStartDate, this.fpCanada); //en-CA

Error: System.FormatException: String was not recognized as a valid DateTime.

I don't want to have to modify the code to use TryParseExact or the registry, so my conclusion was to modify the PC's regional settings to match that of the old server.

Old server
Current format: English (Canada)
Short date: dd/MM/yyyy

New server
Current format: English (Canada)
Short date: yyyy-MM-DD

After updating the date format of the PC's regional settings to dd/MM/yyyy, I tried resetting the app pool, but that doesn't seem to have done anything.

// Still returns yyyy-MM-dd
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern 

Am I wrong in assuming that the PC's regional settings have a direct correlation to the ShortDatePattern in .Net?

MPaul
  • 2,553
  • 3
  • 20
  • 34
  • Are you talking about the culture on the web server or the client? – DavidG Dec 23 '16 at 15:31
  • Web server as that's where the code is hosted – MPaul Dec 23 '16 at 15:35
  • 1
    " so my conclusion was to modify the PC's regional settings to match that of the old server." - are you certain that you changed the regional settings system-wide and for all already-existing users? Note that culture settings are also per-user, and if the user account already exists then the old settings still apply until you delete or update that user's registry file. Remember that the user-account the application pool runs under is its own Windows User, even if it doesn't appear in the Users control panel (e.g. Service Identities). – Dai Dec 23 '16 at 15:52
  • You are correct, modifying the registry solved the problem – MPaul Dec 23 '16 at 16:09

1 Answers1

0

PC Regional and Language Settings are being ignored in .Net

I suspect you are running the application under an identity without its own profile, and it is using the default regional settings stored in the registry under 'HKEY_USERS.Default\Control Panel\International`.

Community
  • 1
  • 1
MPaul
  • 2,553
  • 3
  • 20
  • 34