I have a following cyclic dependencies between two classes in my object graph:
[DataContract]
[KnownType(typeof(Person))]
public class Company
{
[DataMember]
private IList employeesList;
private IList EmployeesList
{
get
{
if (employeesList == null)
{
employeesList = new ArrayList();
}
return employeesList;
}
set { employeesList = value; }
}
public void AddEmployee(Person person)
{
person.Company = this;
EmployeesList.Add(person);
}
}
[DataContract]
public class Person : IEntity
{
private Company company;
[DataMember]
public Company Company
{
get { return company; }
set { company = value; }
}
}
And I have a ServiceOperation that returns a Company, and when that Company contains Persons in its employeeList i get the following error when calling that service operation:
"Error while trying to serialize parameter http://Solo.Service:GetCompaniesByNameResult. Object graph for type 'Solo.Core.Company' contains cycles and cannot be serialized if reference tracking is disabled"
Is there any way around this Is there such thing as enabling reference tracking"
Greg

Error while trying to serialize Cyclic Dependencies
innivodave
My mistake. You need to subclass DataContractSerializerOperationBehavior to enable PreserveObjectReference. I do have a sample lying around. I will clean it up and publish it.
Sorry about it.
cpf
Sowmy,
I'm not sure how that post is relevent because if I understood it, the guy was creating a method to use the DataContractSerializer to serializing his object graph. I'm running into the same error he did but for me it's when I invoke the service operation.
Or, are you implying that I need to add a a <system.runtime.serialization> sectioin to my config to change the default behavior of the DataContractSerializer If so, could you please supply an example of the config that I may need
Thanks,
Greg
Marcelh
Sowmy,
That sounds great! Thanks again for your help. I'll anxiously await your sample.
Greg
KABay
I have posted the sample at http://blogs.msdn.com/sowmy/archive/2006/03/26/561188.aspx
I hope this helps.
srikanthb
Please see
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=305238&SiteID=1
Thanks
Vasen_c
This was exactly what I was looking for. Thank you Sowmy!
Don't you think the [ReferencePreservingDataContractFormat] attribute should be provided out of the box After all, I find that bidirectional references are a somewhat common occurance among parent/child type objects (i.e. the Company.EmployeeList above)
Anyhow, until that happens. Thanks for your help.
Greg