Maximum number of items that can be serialized or deserialized in an object graph... with knowtypes

Pablo Castilla picture Pablo Castilla · Feb 8, 2012 · Viewed 17.8k times · Source

In a WCF 4.0 service we receive a huge amount of data in a generic list. This list object graph is bigger than the 65536 default limit. We are quite used to it, so we have configured the service for being able to getting those big graphs.

<serviceBehaviors>
    <behavior>
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>

With the above chunk of xml config we have avoided the problem in the past with no problem, but now it doesn't work. The only difference is that here we are using KnownTypes in the huge list elements that we are trying to deserialize in the WCF method.

Maybe, am I missing some special configuration for knowntypes?

Answer

Michael Freidgeim picture Michael Freidgeim · Oct 28, 2012

Don't forget to check client configuration.

See similar answers in How to fix MaxItemsInObjectGraph error?

You need to set the MaxItemsInObjectGraph on the dataContractSerializer using a behavior on both the client and service.

and maxItemsInObjectGraph ignored

I had forgot to place this setting in my client app.config file

.