C# driver 1.1.0.4184 and DateTime.MaxValue (potential showstopper)

226 views
Skip to first unread message

Gabriel Duford

unread,
Jun 27, 2011, 2:36:05 PM6/27/11
to mongod...@googlegroups.com
Hi,
I tried to update to the C# driver version 1.1.0.4184 and encountered a potential showstopper.
We have some DateTime.MaxValue persisted in the database with the previous version of the driver. The value persisted is:
253402300800000
After migrating to the new version, we get an overflow exception "MillisecondsSinceEpoch value is after DateTime.MaxValue." in BsonDateTime.cs line 99. Looking at the code, it seems the computed value for DateTime.MaxValue in the new version is
253402300799999 (<=> BsonUtils.ToMillisecondsSinceEpoch(DateTime.MaxValue)
There is a 1 millisecond difference. This makes it impossible to load a DateTime.MaxValue persisted with a previous version of the driver.
Can someone confirm the problem or if this is a know issue?
Thanks,

gabriel

Robert Stam

unread,
Jun 27, 2011, 3:22:43 PM6/27/11
to mongodb-user
It wasn't a known issue (although it's known now!).

Turns out the value the 1.0 driver was writing was incorrect (it is
outside the valid range on .NET DateTime values). Instead of
253402300800000 it should have been writing 253402300799999. This was
fixed as part of the work done to allow the BsonDateTime class support
the *full* range of BSON DateTime values, which is much larger than
the range of .NET DateTime values (although with lower precision).

What was missed in making this fix was the impact on programs reading
existing DateTime.MaxValue values.

I've created a JIRA ticket for this issue:

https://jira.mongodb.org/browse/CSHARP-258

Probably can't be fixed until next week though.

Gabriel Duford

unread,
Jun 27, 2011, 3:27:01 PM6/27/11
to mongod...@googlegroups.com
Thanks Robert.
I commented in the JIRA issue.

gabriel

Robert Stam

unread,
Jul 5, 2011, 4:20:09 PM7/5/11
to mongodb-user
I have implemented a fix for this. See the JIRA ticket for comments:

https://jira.mongodb.org/browse/CSHARP-258
Reply all
Reply to author
Forward
0 new messages