I have a class, ClassA
which has a property which contains types of ClassB
which has a field which is of Type ClassA
. When I tried to serialize this via WCF I got an exception due to the recursive nature of this. The solution was to add IsReference=true
to the data contract definition of ClassA
.
This is great except I have members of ClassA
which are marked with the DataMember(IsRequired=true)
attribute and once I added the IsReference=true
it then complained that things can't be both IsReference=true
and have members which are IsRequired=true
.
I can't understand why this would be and I would like to know if there is a workaround for this?
I'd like to declare my datamembers so that they required in the xml?
I have seen this post already, but the answer is still not clear to me. If I want to prevent default values from being emitted then I can use the EmitDefaultValues=false along side the IsRequired=true (which is what I want to do anyway). Is there another workaround?