Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while deserializing the object in WCF

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.

like image 934
Anil Avatar asked Jul 21 '26 12:07

Anil


2 Answers

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.

like image 143
Adi Avatar answered Jul 23 '26 02:07

Adi


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

like image 20
Dude Pascalou Avatar answered Jul 23 '26 02:07

Dude Pascalou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!