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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With