locked
DateTime.TryParse not working on Windows Server 2012 RRS feed

  • Question

  • I have an old and heavy windows application where DateTime.TryParse(string value, out result) is used extensively.

    Below code runs smoothly on Windows 7 and Windows 10. 

    System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-AU"); // this is done when application starts

    // Below is just an example or one of the way we have been using it. Here success is true and result is-> 20/02/2020 12:00:00 AM

    var success = DateTime.TryParse("20 02", out result);

    But above statement returns false when executed on Windows Server 2012 R2 Standard.

    Appears like Win Server 2012 has broken the DateTime.TryParse. Interestingly if I use .netFrameork 3.5 then it works in all OS. But we are on framework v4.6.2 (VS-2019).

    Is this a bug in Microsoft OS or .netFramework 4.6 ? Is there any existing workaround for this without making much changes in code, may be a .net framework patch etc. Honestly it will be difficult for me to make any changes in code related to this as its usage is more 10,000 in application.

    Thanks in advance !!!

    Friday, April 10, 2020 10:22 AM

Answers

All replies

  • Hello,

    The following blog post is extremely similar to what you found and would think what is discussed is linked to your issues with TryParse although they focus on TryParseExact coupled with Framework 4.6. The key is culture settings which you are doing in your application.

    http://www.heikniemi.net/hardcoded/2015/08/windows-10-breaks-net-date-parsing-in-certain-locales/

    Also consider that SQL-Server 2012 has reached end of life support wise so doubtful that there would be any foreseeable patches.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Proposed as answer by CoolDadTx Friday, April 10, 2020 1:16 PM
    Friday, April 10, 2020 11:46 AM
  • Thanks for replying Karen.

    I have explored the link provided above but somehow it does not answer to my question specifically. Also I am using en-Au culture which is not at all mentioned in that link. Did tried to get the patch also but it is no more available.

    Also I am trying to run the application on Windows Server 2012 R2 which is up to date (last available patch KB3000850 was run on March 2020)  and will be supported by Microsoft at least till October 2023.

    Is it possible to get a .net framework patch for Windows Server 2012 to rectify this breaking changes ?

    Thanks again,

    Harshit

    Friday, April 10, 2020 7:11 PM
  • Thanks for replying Karen.

    I have explored the link provided above but somehow it does not answer to my question specifically. Also I am using en-Au culture which is not at all mentioned in that link. Did tried to get the patch also but it is no more available.

    Also I am trying to run the application on Windows Server 2012 R2 which is up to date (last available patch KB3000850 was run on March 2020)  and will be supported by Microsoft at least till October 2023.

    Is it possible to get a .net framework patch for Windows Server 2012 to rectify this breaking changes ?

    Thanks again,

    Harshit

    I wasn't expecting you to see this specifically answering your question. Windows server update information is found here (not exactly what you asked).

    https://support.microsoft.com/en-us/help/4009470/windows-8-1-windows-server-2012-r2-update-history


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, April 10, 2020 7:42 PM
  • Hi Harshit_S_a,
    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools, and it does not involve Windows Server. I will move it to "where is the forum for" form and the case will be redirected to correct forum.
    Thank you for your understanding.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 13, 2020 5:35 AM
  • Perhaps ask here:

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=netfxbcl


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Friday, April 17, 2020 2:36 PM
  • Might also try asking for help over here.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=netfxsetup

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=windowsgeneraldevelopmentissues

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    Friday, April 17, 2020 3:02 PM