M
MioTheGreat
I know how to take a single hashtable, and then use a binaryformatter
and a filestream to dump it to a file, but I need to serialize and
deserialize a hashtable inside a class. I've been trying this:
[XmlIgnore]
public Hashtable Directions;
public byte[] DirectionsSerialized
{
get
{
byte[] bData = new byte[1024];
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream memoryStream = new MemoryStream(bData);
memoryStream.Position = 0;
formatter.Serialize(memoryStream, Directions);
return bData;
}
set
{
MemoryStream memoryStream = new MemoryStream();
memoryStream.Write(value, 0, value.Length);
BinaryFormatter bf = new BinaryFormatter();
memoryStream.Position = 0;
Directions = (Hashtable)bf.Deserialize(memoryStream);
}
}
Which appears to serialize fine, but upon deserialization, it throws an
error:
"'', hexadecimal value 0x1B, is an invalid character. Line 299,
position 18."
Thanks guys.
and a filestream to dump it to a file, but I need to serialize and
deserialize a hashtable inside a class. I've been trying this:
[XmlIgnore]
public Hashtable Directions;
public byte[] DirectionsSerialized
{
get
{
byte[] bData = new byte[1024];
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream memoryStream = new MemoryStream(bData);
memoryStream.Position = 0;
formatter.Serialize(memoryStream, Directions);
return bData;
}
set
{
MemoryStream memoryStream = new MemoryStream();
memoryStream.Write(value, 0, value.Length);
BinaryFormatter bf = new BinaryFormatter();
memoryStream.Position = 0;
Directions = (Hashtable)bf.Deserialize(memoryStream);
}
}
Which appears to serialize fine, but upon deserialization, it throws an
error:
"'', hexadecimal value 0x1B, is an invalid character. Line 299,
position 18."
Thanks guys.