G
Garrett
The following quote
The only requirement placed on object graphs is that all objects referenced
by the object that is being serialized must also be marked as Serializable
(see Basic Serialization). If this is not done, an exception will be thrown
when the serializer attempts to serialize the unmarked object.
appears at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/objserializ.asp
However when I run code which tried to serialize an object, no exception was
thrown. Instead the
code just seemed to hang. (version 1.1)
Anyone know what's wrong?
Thanks.
Garrett
Sample code follows:
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
//[Serializable]
public class Stuff{
public String Name;
}
class Test {
[STAThread]
static void Main(string[] args) {
Stuff mystuff = new Stuff();
mystuff.Name = "Try this";
MemoryStream ms = new MemoryStream(); //memory stream
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, mystuff);
ms.Position = 0;
Stuff s = (Stuff)bf.Deserialize(ms);
Console.WriteLine(s.Name);
}
}
The only requirement placed on object graphs is that all objects referenced
by the object that is being serialized must also be marked as Serializable
(see Basic Serialization). If this is not done, an exception will be thrown
when the serializer attempts to serialize the unmarked object.
appears at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/objserializ.asp
However when I run code which tried to serialize an object, no exception was
thrown. Instead the
code just seemed to hang. (version 1.1)
Anyone know what's wrong?
Thanks.
Garrett
Sample code follows:
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
//[Serializable]
public class Stuff{
public String Name;
}
class Test {
[STAThread]
static void Main(string[] args) {
Stuff mystuff = new Stuff();
mystuff.Name = "Try this";
MemoryStream ms = new MemoryStream(); //memory stream
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, mystuff);
ms.Position = 0;
Stuff s = (Stuff)bf.Deserialize(ms);
Console.WriteLine(s.Name);
}
}