[Mono-bugs] [Bug 649620] New: Invalid serialization of datetime

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Oct 27 12:01:15 EDT 2010


https://bugzilla.novell.com/show_bug.cgi?id=649620

https://bugzilla.novell.com/show_bug.cgi?id=649620#c0


           Summary: Invalid serialization of datetime
    Classification: Mono
           Product: Mono: Runtime
           Version: SVN
          Platform: 64bit
        OS/Version: RHEL 5
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: misc
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: srfcanada at hotmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; WOW64;
Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; MS-RTC LM 8)

the following test case works on windows but fails on mono. Note that this used
to work as of a couple weeks ago so it seems to have been broken recently.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Diagnostics;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.IO;

   class monofail6
   {
      static int Main(string[] args)
      {

         DateTime dtm = new DateTime(2010, 7, 7, 10, 10, 10, 10,
DateTimeKind.Local);
         LocalDateTime localDateTime = new LocalDateTime(dtm);

         BinaryFormatter bf = new BinaryFormatter();
         MemoryStream ms = new MemoryStream();
         bf.Serialize(ms, localDateTime);
         ms.Position = 0;

         LocalDateTime dateTime2 = (LocalDateTime)bf.Deserialize(ms);

         Console.WriteLine("Original Date:" + dtm.ToString());
         Console.WriteLine("Current  Date:" + dateTime2);

         if (dtm != dateTime2.DateTime)
            throw new Exception("dates are not equal!!");

         Console.WriteLine("Worked!!");
         return 0;
      }

      [Serializable]
      public struct LocalDateTime : ISerializable
      {
         private DateTime m_localDateTime;
         public LocalDateTime(DateTime dt)
         {
            m_localDateTime = dt;
         }

         private LocalDateTime(SerializationInfo info, StreamingContext
context)
         {
            m_localDateTime =
DateTime.FromBinary(info.GetInt64("LocalDateTime"));
         }

         public DateTime DateTime
         {
            get { return m_localDateTime; }
            set { m_localDateTime = value; }
         }

         void ISerializable.GetObjectData(SerializationInfo info,
StreamingContext context)
         {
            info.AddValue("LocalDateTime", m_localDateTime.ToBinary());
         }

         public override string ToString()
         {
            return m_localDateTime.ToString();
         }
      }

   }


Reproducible: Always

Steps to Reproduce:
1.
2.
3.

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list