XmlSerialization creates a serializer proxy for each class. The proxy resides in a different assembly so it can serialize only public fields.
DataContract serialization can serialize private fields too. Does it mean it uses reflection? Isn’t it slower than using a proxy (except for the first time)?
This protobuf-net page shows the performance of
DataContractSerializerto be significantly better thanXmlSerializer. Of course, you should always test with your own data, but if you are looking to replaceXmlSerializer, you will most likely findDataContractSerializerto be a performance improvement.I’m not sure how
DataContractSerializeris implemented internally, but generally serializers are highly optimized. This is especially true forDataContractSerializersince it is a big part of the performance picture for WCF. It is not uncommon for a serializer to generate MSIL code on the fly. When this is done,DynamicMethodallows you to (surprisingly!) bypass visibility checks (see MSDN), so it is possible to access private fields without reflection.From MSDN: