Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Sep 05, 2014 @ 23:38
    Nicholas Westby
    0

    Rare Date Parse Error When Submitting Comment

    I am sometimes getting an error with uCommentsy and this in my error log:

    2014-09-05 14:06:39,030 [8] INFO umbraco.BusinessLogic.Log - [Thread 23] Redirected log call (please use Umbraco.Core.Logging.LogHelper instead of umbraco.BusinessLogic.Log) | Type: Error | User: 0 | NodeId: 12954 | Comment: String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider provider) at uCommentsy.BusinessLogic.Models.Subscription..ctor(Member member, String[] items) in c:\Users\Nick\Desktop\anthonydotnet-ucommentsy-ac4be9e4b684\anthonydotnet-ucommentsy-ac4be9e4b684\Source\uCommentsy.BusinessLogic\Models\Subscription.cs:line 45 at uCommentsy.BusinessLogic.Extensions.MemberExtensions.<>c__DisplayClass3.

    The problem seems to be in the Subscriptions constructor when you parse a date: https://bitbucket.org/anthonydotnet/ucommentsy/src/ac4be9e4b68428419fae78c20af514a6e0362b65/Source/uCommentsy.BusinessLogic/Models/Subscription.cs?at=default#cl-45

    Notice in the catch block you parse the date using the current culture. Sometimes the DateTime.Parse function can get confused with things like the order of the days/months/years. I recommend you store dates in something like this format: http://en.wikipedia.org/wiki/ISO_8601

    And you can parse dates using DateTime.ParseExact rather than DateTime.Parse. Also, might want to add an extra try block around that second parse and figure out some behavior that should take place if the date could not be parsed.

    By the way, I think the error log is showing a path to code on my desktop because I had to recompile uCommentsy to work with Umbraco 7. In case the above error log text is hard to read, here's a screenshot of the error log: enter image description here

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Sep 07, 2014 @ 00:59
    Anthony Dang
    0

    You're only sometimes getting this error?

    Do you have a multi-country site? Could it be different date formats?

     

     

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Sep 07, 2014 @ 02:17
    Nicholas Westby
    0

    Yeah, I only saw it a few times. Went away when I deleted all comment nodes under the page I was trying to post to and emptied my recycle bin.

    No, it's a single-country site. Though, there's no guarantee that all the servers it's been run on will use the same date format (we have dev machines, a staging server, and a production server). I'm thinking the date format should not care about the machine the website runs on.

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Sep 07, 2014 @ 17:18
    Anthony Dang
    0

    Strange. 

    If it happens again, and you can replicate it, please let me know.

Please Sign in or register to post replies

Write your reply to:

Draft