Search

(De)Serialization of an instance of a class implementing IComparable does not work. by DiegoGLagash

Closed
as Won't Fix Help for as Won't Fix

1
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 91177
Opened: 1/3/2006 1:08:42 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
The following code does not work successfully.

using System;
using System.IO;
using System.Xml;
using System.Runtime.Serialization.Formatters.Binary;

namespace ConsoleApplication1
{
    class Class1
    {
        [Serializable]
        public class SomeClass : IComparable
        {
            public IComparable Value;
            #region Miembros de IComparable
            public int CompareTo(object obj)
            {
                return 0;
            }
            #endregion
        }

        static void Main(string[] args)
        {
            // esto anda
            BinaryFormatter fmt = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            SomeClass str = new SomeClass();
            str.Value = "s"; // aca le paso un string
            fmt.Serialize(ms, str);
            ms.Seek(0, SeekOrigin.Begin);
            object a = fmt.Deserialize(ms);

            // esto no
            ms = new MemoryStream();
            str = new SomeClass();
            str.Value = 12; // aca un int
            fmt.Serialize(ms, str);
            ms.Seek(0, SeekOrigin.Begin);
            object a2 = fmt.Deserialize(ms);
        }
    }
}

The strangest issue is that changing the definition of "public IComparable Value;" to "public object Value;" make it work.
Details (expand)
Product Language
English
Version
Visual Studio 2005
Category
CLR
Operating System
Windows XP Professional
Operating System Language
US English
Steps to Reproduce
Compile and run the previous code and it will throw an exception
Actual Results
Unhandled Exception: System.Runtime.Serialization.SerializationException: End of
Stream encountered before parsing was completed.
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(He
aderHandler handler, __BinaryParser serParser, Boolean fCheck, IMethodCallMessag
e methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize
(Stream serializationStream, HeaderHandler handler, Boolean fCheck, IMethodCallM
essage methodCallMessage)
at MainClass.Main()
Expected Results
Reference a2 must be set correctly.
File Attachments
0 attachments
Sign in to post a comment.
Posted by DiegoGLagash on 1/3/2006 at 3:58 PM
Code updated to remove spanish comments (sorry for this).

using System;
using System.IO;
using System.Xml;
using System.Runtime.Serialization.Formatters.Binary;

namespace ConsoleApplication1
{
    class Class1
    {
        [Serializable]
        public class SomeClass : IComparable
        {
            public IComparable Value;
            public int CompareTo(object obj)
            {
                return 0;
            }
        }

        static void Main(string[] args)
        {
            // it does work
            BinaryFormatter fmt = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            SomeClass str = new SomeClass();
            str.Value = "s"; // a string
            fmt.Serialize(ms, str);
            ms.Seek(0, SeekOrigin.Begin);
            object a = fmt.Deserialize(ms);

            // it does not work
            ms = new MemoryStream();
            str = new SomeClass();
            str.Value = 12; // an int
            fmt.Serialize(ms, str);
            ms.Seek(0, SeekOrigin.Begin);
            object a2 = fmt.Deserialize(ms);
        }
    }
}
Posted by Microsoft on 1/13/2006 at 5:58 PM
Thank you for submitting this issue. We will investigate and consider fixing in a future version of the Framework.
-- Eugene Osovetsky, Program Manager, XML Messaging / Serialization
Posted by Microsoft on 12/4/2006 at 10:10 AM
Thank you for submitting this issue. Unfortunately, we have decided that it will not be addressed because the risk of the fix outweighs its benefit. By the time the next opportunity to make this change comes about, the hope is that the new serialization technologies in a future version of the Windows Communication Foundation will address your scenario. If this issue is causing significant negative business impact, please contact Microsoft Product Support Services. I regret that we could not provide a better resolution. Rest assured that we seriously considered this issue - a Won't Fix decision is never easy to make.
-- Eugene Osovetsky, Program Manager, XML Messaging / Data