Unexpected value of RemotingFormat property after being deserialized

C

Carl Johansson

How come the RemotingFormat property of the DataTable object has a
value of SerializationFormat.Xml? Please see the code below:

private static void WriteDataTableToBinary(DataTable dataTable)
{
dataTable.RemotingFormat = SerializationFormat.Binary; // Defaults
to "SerializationFormat.Xml".
dataTable.TableName = "SerializedTable";
BinaryFormatter binaryFormatter = new BinaryFormatter();
using (FileStream fileStream = new FileStream(@"C:\Data\Temp
\TableData.bin", FileMode.Create, FileAccess.Write))
binaryFormatter.Serialize(fileStream, dataTable);
}

private static DataTable ReadDataFromBinary()
{
BinaryFormatter binaryFormatter = new BinaryFormatter();

using (FileStream fileStream = new FileStream(@"C:\Data\Temp
\TableData.bin", FileMode.Open, FileAccess.Read))
{
DataTable dataTable =
(DataTable)binaryFormatter.Deserialize(fileStream);

// Why "SerializationFormat.Xml", when it was
"SerializationFormat.Binary" when serialized???
Console.WriteLine(dataTable.RemotingFormat);

// In contrast, the TableName property has the expected value.
Console.WriteLine(dataTable.TableName);

return dataTable;
}
}

Regards Carl Johansson
 
C

Carl Johansson

It seems to me that the most obvious answer is simply that the
RemotingFormat property isn't among the data that are serialized when a
DataTable is serialized.

Yes, of course, why didn't I think of that!? I guess it has been too
long since I serialized anything... Thanks!

Regards Carl Johansson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top