Reputation: 9621
I am calling a WCF service from a asp.net application.
My save operations were failing and I was getting an error which said I have to set an attribute:
[DataContract(IsReference = true)]
Now my save operation works, but my get operation (returns a collection) returns a collection but the properties are all nulled out.
If I have:
[Serializable]
The get operation works, but the save fails with:
System.Runtime.Serialization exception "contains cycles and cannot be serialized if reference tracking is disabled."
How can I get around this issue? I can't have both attributes either obviously.
Upvotes: 2
Views: 1345
Reputation: 1345
As far as I can understand based on the small pieces of code, this could be a circular reference issue. Reading around I realized that up until some time ago you had to implement your own DataContractSerializer (see for example this post by Sowmy Srinivasan).
With NET 3.5 SP1 everything is much simpler: you just have to use the IsReference parameter in the DataContract attribute, as follows:
[DataContract(Namespace = "http://schemas.acme.it/2009/10", IsReference=true)]
public class Node
{
// everything same as in the example above.
}
For some reason, if you turn on the IsReference attribute, then you cannot set the IsRequired attribute to true on any DataMember of the DataContract. The reason is somehow explained here (archived).
Hope this can free you out of this issue ;-)
Upvotes: 2