0

When serialising an object using Data Contracts I am hitting an issue with circular references. I know about using IsReference=true but I can't use this as I'm inheriting from object that I don't have control over. Is there any way to get around, can I count the times and exit, like a for break?

Phil Whittaker
  • 434
  • 4
  • 20

2 Answers2

1

Implementing a custom DataContractSerializerBehavior as suggested here: Circular References and WCF should fix it I think?

Updated for non-WCF:

The solution in the linked answer is based on using:

new DataContractSerializer(type, name, ns, knownTypes,
                          0x7FFF //maxItemsInObjectGraph,
                          false //ignoreExtensionDataObject,
                          **true** //preserveObjectReferences,
                          null //dataContractSurrogate);

Using this constructor should fix it I think.

Community
  • 1
  • 1
Olav Nybø
  • 11,454
  • 8
  • 42
  • 34
  • I'm not using wcf, its just serialising using the DataContractSerializer. How could I implement the solution for this situation? – Phil Whittaker May 17 '12 at 08:53
-2

You can use WeakReferences?

http://msdn.microsoft.com/pt-br/library/system.weakreference.aspx

Tiago Peczenyj
  • 4,387
  • 2
  • 22
  • 35