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

2

14

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?

Lintwhite answered 16/1, 2012 at 7:7 Comment(0)
L
11

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!

Lush answered 7/5, 2012 at 8:21 Comment(1)
Although JSON.Net can handle IsReference=true. dotnet.learningtree.com/2012/04/03/…Zoubek
H
1

I think that nothing bad should happen. If your graph contains more than one link to the same object instance, setting this attribute to true will reduce XML size.

http://zamd.net/2008/05/20/datacontract-serializer-and-isreference-property/

However I am not sure why it is not enabled by default.

Helper answered 17/1, 2012 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.