views:

51

answers:

3

Some things in .NET are called "formatters" - BinaryFormatter, SoapFormatter.

Others are called "serializers" - XmlSerializer, DataContractSerializer.

Why the difference?

+3  A: 

No, they are synonyms. They do the same: convert CLR object to transferable sequence of bytes.

Andrey
Andrey: nice - short and sweet... :) +1
tommieb75
A: 

The differences in the formatters is crucial - BinaryFormatter as it suggests, the data are in native binary fashion, whereas SoapFormatter is in Xml text fashion, throw in the different ways of serializing is actually dependent on the type of formatters, binary data using BinaryFormatter tend to be a lot smaller and faster than soap formatters.

It is for that reason, if you want to take a "memory dump" it is better to use BinaryFormatter and serialize/deserialize away, at the cost of data interoperability between different architectures - meaning it may not be compatible if exchanging data between different platforms BUT faster processing...

Whereas with SoapFormatter it is protected from such binary incompatibilities as it is text based on either Unicode or ASCII, but much slower!

tommieb75
Good answer, but not really an answer to the question...
Kendrick
@Kendrick - ok... thanks... well when the OP asked 'Why the difference?' I thought this would be what the OP is looking for rather than 'No, they are synonyms' by Andrey, which kind of contradicts 'They do the same' when really the definition of synonym is 'Synonyms are different words with identical or very similar meanings' not necessarily the same! :)
tommieb75
No, Kendrick is correct - I know the difference in functionality. What I'm asking about is the inconsistency in naming. Thanks though.
Stefan Monov
@Stefan: Fair enough then so! Pleasure to write up the answer nonetheless! :)
tommieb75
i stil think that they are essentially same. you just gave difference between particular classes.
Andrey
@Andrey: aye.... :)
tommieb75
+2  A: 

A bit tenuous, but there is a subtle difference. There are 17 concrete classes in the .NET framework that format XML. These formatters are all hidden, you get an instance to them with a method like XmlWriter.Create(). Same for DataContractSerializer, the actual formatting is done by, say, an XmlDictionaryWriter instance.

No such indirection for BinaryFormatter or SoapFormatter, they take care of the formatting themselves. In other words, a Formatter formats, a Serializer uses a formatter.

Hans Passant
Interesting. Where can I read about the 17 classes that format XML?
Stefan Monov
They are not documented. But you can see them with Reflector.
Hans Passant