Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does DataContractSerializer not implement IFormatter?
    text
    copied!<p>I'm getting a bit frustrated by the lack of consistency within the different forms of serialization in .NET:</p> <ul> <li><p>DataContractSerializer - uses new attributes OR old [Serializable] attributes, but the serializer itself does not implement IFormatter where some of the other WCF serializers do. Opt IN.</p></li> <li><p>NetDataContractSerializer - uses new attributes OR old, serializer implements IFormatter, is compatible with WCF, and is Opt IN. Seems like the ideal solution!</p></li> <li><p>XmlSerializer - totally independant set of attributes, but is legacy so can forgive this.</p></li> <li><p>BinaryFormatter - implements IFormatter and uses the [Serializable] attributes. Opt OUT.</p></li> </ul> <p>So my question is, why does DataContractSerializer not stay at least fairly interchangable with BinaryFormatter? </p> <p>I really wish they'd settled on a nice clean interface for this from the start, its a shame really in the expanse of the .NET framework which is usually so ordered!</p> <p>Edit: Just for those who are interested (I know this isnt really relevant to the rest of the topic), I've been doing some both time and size benchmarking of what I perceive as the most likely "on-the-wire" serialization methods:</p> <pre><code>============ Serialization ============ Protobuf x158,194 39,549 per/sec 1.00 OldFieldbase x58,191 14,548 per/sec 2.72 Fieldbase x57,445 14,361 per/sec 2.75 DataContract x54,611 13,653 per/sec 2.90 Binary x29,466 7,367 per/sec 5.37 Net x28,170 7,043 per/sec 5.62 Json x10,605 2,651 per/sec 14.92 </code></pre> <p>And sizes:</p> <pre><code>============ SerializationSizes ============ Protobuffers 209 bytes 1.00 Fieldbase 246 bytes 1.18 OldFieldbase 248 bytes 1.19 Json 728 bytes 3.48 DataContract 1227 bytes 5.87 Net 1658 bytes 7.93 Binary 1826 bytes 8.74 </code></pre> <p>NOTE: On a Core2 T9300 (single threaded) + 4GB.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload