I have tested the dataset new "binary serialize" feature in ADO.Net 2.0. Many articals said if we set the dataset's property "RemotingFormat" as "SerializationFormat.Binary", it can serialize itself in binary format.

OK, this propety works well, the output file is much smaller than xml style.

But i got something strange:
If i first set a dataset "RemotingFormat" as "binary" before serialize it into a file, then Deserialize it to a new dataset , the new dataset's "RemotingFormat" value is missing, it become the default value: "XML"!!! 

Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   BinaryFormatter bf = new BinaryFormatter();
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   FileStream fs 
= new FileStream(System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "ds.dat", FileMode.OpenOrCreate);
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   DataSet ds 
= GiveMeFakeData();
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   ds.RemotingFormat 
= SerializationFormat.Binary;
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   bf.Serialize(fs, ds);
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   fs.Close();
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   
// Check the deserialization performance.
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)
   fs = new FileStream(System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "ds.dat", FileMode.Open);
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   
long nowticks = DateTime.Now.Ticks;
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   DataSet ds2 
= (DataSet)bf.Deserialize(fs);
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   
//note here!
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   
//ds2.RemotingFormat == SerializationFormat.XML!
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)

Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   
long tickstotal = DateTime.Now.Ticks - nowticks;
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   Console.WriteLine(
"Took me : " + tickstotal);
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)   fs.Close();
Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0)

Then i dig into the source code, i have found  

Why does Dataset NOT serialize its BinaryFormat property? (ADO.net 2.0) private void SerializeDataSetProperties(SerializationInfo info, StreamingContext context)


It looks like the dataset didn't serialize the RemotingFormat Property.

Anyone knows why it like this? Is it a bug or a design decision?

(have reported this issue to MS)

Updated: 2005/9/26

The ADO.net PM (Kawarjit Bedi) has replied this issue:

=== QUOTE ===

The primary motivation for doing that were:
1. Backward compatibility. If a v2.0 client recives DataSet from v2.0 server using BinaryRemoting (set at server side - the client does not know it) and then sends the same DataSet to v1.x client without resetting the RemotingFormat property to XML, it'd break the v1.x client. With the default behavior, it'd not break this case.
2. The value of RemotingFormat property is a like a parameter being passed to the remoting engine, it's more to do with the remoting operation then the DataSet's state, hence the reluctance to serialize the property.

=== END QUOTE ===

So, this is not a bug but a design decision.

Thanks Kawarjit :)

相关文章: