简体   繁体   中英

C# method DateTime.TryParse() behaves differently on same machine in BizTalk versus Console app

Consider the following lines of code:

DateTime d;
DateTime.TryParse("16-10-2020", out d);

When run inside a console app the date time 16-10-2020 00:00:00 is returned. Culture nl-NL is used, as defined in my windows regional settings. However, when run inside a Biztalk 2016 pipeline component on a 64 bit hostinstance, 16-10-2020 is not a valid date. Upon inspection it appears culture en-US is used to parse the date string. I did not explicitly specify any culture to be used in my code, therefore expecting nl-NL to be used by BizTalk as well.

Both scenario's are running on identical .NET Framework version on the same machine. What explains the difference in behavior?

I cannot find any specific culture configuration in my BizTalk server config. Could it be that BizTalk stored culture info somewhere I am unaware of during installation, but failed to update when regional settings changed? Just guessing. Anybody?

The BizTalk service account had different regional settings than my user, which explained the difference in behavior.

Better use TryParse exact if the format is known upfront.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM