[Mono-dev] Need advice for bug 325067 (DateTime binary serialization incompatible with MS.NET 2.0)

Lionel Cuir lionel_email at aulofee.com
Sat Jun 7 10:33:12 EDT 2008


Hello All,

I'm having a look at bug 325067 as it's still a major issue for my company.

- I've reread the whole thread and must say I'm not sure to understand 
its current status. If I'm not wrong, the open issue relates to the 
direct serialization of a DateTime (ie with a DateTime as the top of the 
serialization tree), and the question for this is to know who is going 
to be binary compatible with whom (ie Mono CLR v2 binary compatible with 
either MS .Net 2.x or with Mono CLR v1). Has anything been decided for 
this ? Could someone kindly advise me ?

- Additionally, it's said in the post that when Mono and MS .Net would 
be binary compatible for DateTime when a DateTime is not a the top of 
the serialization tree or when using the To/FromBinary methods. I've 
just tested this and found anomalies, where the deserialized DateTime is 
not the expected ones in Mono when the DateTimeKind of the date is 
LocalTime (if the date is in UTC, that's ok). Before to call it a bug, 
could anybody tell me if I'm not making a dummy mistake?

        To reproduce it:
        1. Serialize a DateTime into a file in MS.Net:
                DateTime testDate = new DateTime(1975, 8, 14, 14, 0, 0,
        DateTimeKind.Local);
                using (FileStream fs = File.Create("myfile.bin"))
                    bf.Serialize(fs, new KeyValuePair<string,
        DateTime>("dummytxt", testDate));

        2. Deserialize it in MS.Net (Windows) and Mono (Linux)
                    using (FileStream fs = File.OpenRead("myfile.bin"))
                    {
                        KeyValuePair<string, DateTime> kvp =
        (KeyValuePair<string, DateTime>)bf.Deserialize(fs);
                        Console.WriteLine("Date read: " + kvp.Value + "
        " + kvp.Value.Kind);
                        Console.WriteLine("        in UTC: " +
        kvp.Value.ToUniversalTime().ToString());
                    }

        In windows, I get what's expected:
            Date read: 14/8/1975 14h Local time
            in UTC: 14/08/1975 12:00:00

        In Debian, I get wrong results:
            Date read: 14/8/1975 15h Local time
            in UTC:  14/08/1975 14:00:00

        It seems that the DateTimeKind has not been taken into account.
        Isn't it a bug?
        (Note: both Windows and Debian are set to Europe/Paris (UTC+2)
        time zone)

        Even worst, if I use ToBinary/FromBinary to exchange the
        DateTime between Windows/.Net and Linux/Mono, I get another
        different result in Linux:
            Date read: 14/8/1975 13h Local time
            in UTC:  14/08/1975 12:00:00
        => UTC time is correct, but the local time is only UTC+1 whereas
        my Debian is in UTC+2 (date => mercredi 7 mai 2008, 16:21:03
        (UTC+0200) )

Life is a long quiet river...

Thanks for the help
Lionel


More information about the Mono-devel-list mailing list