I have made my own custom class to SERIALIZE and DE-SERIALIZE a custom object (kind of complicated, the object contains a custom array of custom objects, etc... lets just say I pretty much had to add [Serializable] at the top of all my objects).
Now the Serialization seems to work perfectly fine HOWEVER when I attempt to de-serialize the data on the other side (I send the data from the SERVER to the CLIENT via a TCP-Channel) I keep getting some odd errors regarding "objectID cannot be less than or equal to zero"
Anyways, this is the class I use to perform my Serialization
And this is the exact EXCEPTION error message I get (when caught) in the "Deserialize" function above...
[Exception]
Deserialize:: General Exception: System.ArgumentOutOfRangeException: objectID cannot be less than or equal to zero.
Parameter name: objectID
at System.Runtime.Serialization.ObjectManager.GetObject(Int64 objectID)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseArrayMember(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseMember(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadMemberReference()
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
at Application.Serialization.Deserialize(Byte[] data)
[/Exception]
I am totally lost and I can't seem to find any information regarding this type of error...
I must admit this is my first attempt at Serialization/DeSerialization of custom objects but I would have assumed it would work fine...
Any ideas, hints, and help would be greatly appreciated, thanks
Now the Serialization seems to work perfectly fine HOWEVER when I attempt to de-serialize the data on the other side (I send the data from the SERVER to the CLIENT via a TCP-Channel) I keep getting some odd errors regarding "objectID cannot be less than or equal to zero"
Anyways, this is the class I use to perform my Serialization
Code:
public class Serialization
{
static private BinaryFormatter bf = new BinaryFormatter();
public static byte[] Serialize(object data)
{
try
{
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, data);
return ms.ToArray();
}
catch (Exception ex)
{
Log.Trace("Serialize:: General Exception: " + ex);
return null;
}
}
public static object Deserialize(byte[] data)
{
try
{
MemoryStream ms = new MemoryStream(data);
return bf.Deserialize(ms);
}
catch (Exception ex)
{
Log.Trace("Deserialize:: General Exception: " + ex);
return null;
}
}
}
}
And this is the exact EXCEPTION error message I get (when caught) in the "Deserialize" function above...
[Exception]
Deserialize:: General Exception: System.ArgumentOutOfRangeException: objectID cannot be less than or equal to zero.
Parameter name: objectID
at System.Runtime.Serialization.ObjectManager.GetObject(Int64 objectID)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseArrayMember(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseMember(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord pr)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadMemberReference()
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
at Application.Serialization.Deserialize(Byte[] data)
[/Exception]
I am totally lost and I can't seem to find any information regarding this type of error...
I must admit this is my first attempt at Serialization/DeSerialization of custom objects but I would have assumed it would work fine...
Any ideas, hints, and help would be greatly appreciated, thanks