Page 1 of 1

[SOLVED] DateTime bug: Error "cannot construct UInt64 from negative number" exception localized

Posted: Thu Jul 14, 2016 7:25 am
by Sesztak
Dear Support,
We have got a problem with objects with DateTime property:

Background infomation:
WCF communication from Server to CSHTML5 client direction:

if certain object has a DateTime property at the default constructor state the value is something like that from .NET point of view, e.g.:
ValidTimeStamp {0001. 01. 01. 0:00:00} System.DateTime

So, when you try to pass such a value to CSHTML5 client you got exception: Error "cannot construct UInt64 from negative number".

If you do:
ValidTimeStamp = new DateTime(1971, 1, 1); // problem: Kind Unspecified System.DateTimeKind
You will get the same exception.

If you do ValidTimeStamp = DateTime.Now;
No problem at all.

So, as we think the probleblem is coming from the Kind property of DateTime struct:
the first case you will got DateTimeKind = Unspecified, and you got error.

We had a workaround this, e.g.:
ValidTimeStamp = new DateTime(1971, 1, 1).ToUniversalTime();
or:
ValidTimeStamp = new DateTime(1971, 1, 1).ToLocalTime();

Just to avoid Unspecified DateTimeKind property.

Is this an expected behaviour or a kind of bug?
Thanks in advance,
Péter
ps: I hope this info helps to others to avoid from such a bug.

Re: DateTime bug: Error "cannot construct UInt64 from negative number" exception localized

Posted: Sun Jul 24, 2016 11:56 am
by JS-Support @Userware
Thank your for your message.

The DateTime class will be completely rewritten from scratch in a few weeks. I will keep you updated.

Regards,
JS-Support

Re: DateTime bug: Error "cannot construct UInt64 from negative number" exception localized

Posted: Mon Sep 12, 2016 8:43 am
by Sesztak
any progress ?

Re: DateTime bug: Error "cannot construct UInt64 from negative number" exception localized

Posted: Sat Sep 24, 2016 4:00 am
by JS-Support @Userware
Hi,

The issue has been fixed in Beta 9.4, which you can download from the following URL:

http://forums.cshtml5.com/viewforum.php?f=6

Thanks.
Regards,
JS-Support

Re: [SOLVED] DateTime bug: Error "cannot construct UInt64 from negative number" exception localized

Posted: Thu Sep 29, 2016 4:40 am
by rkmore
With regret I must tell you this error still occurs in 9.4 and 10.0

RKM

Re: [SOLVED] DateTime bug: Error "cannot construct UInt64 from negative number" exception localized

Posted: Thu Sep 29, 2016 6:26 am
by Sesztak
Dear rkmore,

just for your information to share our experience (only with v9.4 as v10 is not available for download actually -I do not know why):

Background info : We use DateTime with WCF scenario : in this case CSHTML5 is a Client (consumer) of a WCF service.

We have not been tested every situation with DateTime and v9.4
(e.g. Server side Kind : unspecified, local, utc X Client side: unspecified, local, utc), but for your information:

if you use (as we) UTC for both Server and Client: it's working -based on our experience and intensive tests.

As I feel the problem should come with mixed Server / Clients time zones and mixed usage of time (unspecified, local, utc) at Server / Clients side -but this is only a theory / opinion, do not take it as a fact.


I hope it helps to you at least to find a temporary workaround.

BR,
Péter

Re: [SOLVED] DateTime bug: Error "cannot construct UInt64 from negative number" exception localized

Posted: Thu Sep 29, 2016 10:55 am
by rkmore
Dear Sesztak

You should have received an email with the 10.0 link (don't know why it is not in the message body like all the others). If not drop them a note.

We found that it actually depended on the value of the date time and not even the zone. Two different values work differently. Very strange.

We modified the generated service client code manually and made the value a string instead of a DateTime and that has fixed it at least temporarily (the value is not really used in the web app except to be displayed)

Thanks for the info

RKM

Re: [SOLVED] DateTime bug: Error "cannot construct UInt64 from negative number" exception localized

Posted: Thu Sep 29, 2016 11:41 am
by Sesztak
Dear rkmore,

For your kind information: one important detail what I've forgotten to mention to you:

Remember, that the earliset DateTime in JavaScript 1 January, 1970 UTC.

reference: e.g.:
https://developer.mozilla.org/en/docs/W ... jects/Date

"Date objects are based on a time value that is the number of milliseconds since 1 January, 1970 UTC."

It's a huge limitation comparing C#/CLR.

I mean if you just do such a thing in C# / Server side:
var TimeOfCSharp = new DateTime();
// you will get a value: TimeOfCSharp = {0001.01.01. 0:00:00}
// with Kind = Unspecified (not Local or UTC)
// Oooops !

If you can you can try a workaround:
e.g make an inherited DateTime class with JavaScript word compatible START date,
pseudo code:
class JavaScriptCompatibleDateTime : DateTime
{
+ add a constructor with the 1 January, 1970 UTC date or later.

What do you think, is it help to you?

Best Regards,
Péter