When/Why should I not use IsReference=true on my DataContracts?

Stéphane picture Stéphane · Jan 16, 2012 · Viewed 7.8k times · Source

I understand what is the attribute property IsReference and what it is doing. But I don't understand why/when I should not use it. When is it a bad idea to use IsReference=true?

If my wcf service are .net to .net, is there good reasons to not set IsReference=true?

Answer

Rune Grimstad picture Rune Grimstad · May 7, 2012

There are at least two reasons to avoid using IsReference:

First there is a performance penalty since all the serializer must perform an identity check for each object that is to be serialized.

Second, the DataContractJsonSerializer cannot serialize objects marked with the IsReference attribute. So if you need to support both Xml and Json then you cannot use it.

Apart from those, I don't see any reason not to use it. After all it does save some precious bandwidth!