Error while deserializing the object in WCF

24,447

Solution 1

In my case, the problem was that I was returning Entity Framework objects that I got from the data context. The solution was to detach each object before retuning them.

Solution 2

In my case, detaching objects was not possible because the EF context was already disposed.

Instead, I used the AsNotTracking extension method.

...On some other cases, I also had to cut circular references by setting some navigation properties to null.

...And DataContract(IsReference = true) did not do the trick.

More details on this issue can be found here : N-tier Entity Framework and debugging WCF problems

Share:
24,447
Channa
Author by

Channa

Having 12+ years experience in developing and maintaining large scale Enterprise level applications using Microsoft Technologies.

Updated on July 13, 2020

Comments

  • Channa
    Channa almost 4 years

    I have created a REST Service in WCF. I am facing the following issue

    There was an error deserializing the object of type System.Collections.Generic.IList. The maximum read depth (32) has been exceeded because XML data being read has more levels of nesting than is allowed by the quota. This quota may be increased by changing the MaxDepth property on the XmlDictionaryReaderQuotas object used when creating the XML reader.

    I haven't specified any type of binding in configuration since I have developed the service as per REST Starter Kit. Please suggest something as to how can I fix it.

    The code is working fine sometimes but it do throw error.