Geeks With Blogs

News My Blog has been MOVED to

Michael Freidgeim's OLD Blog My Blog has been MOVED to
We have a wcf service, that expects to return a huge XML data. It worked ok in testing, but in production it failed with error  "Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota."

The MSDN article about   dataContractSerializer xml configuration  element  correctly  describes maxItemsInObjectGraph attribute default as 65536, but documentation for of the 

DataContractSerializer.MaxItemsInObjectGraph property and DataContractJsonSerializer.MaxItemsInObjectGraph Property 

are talking about Int32.MaxValue, which causes confusion, in particular because Google shows properties articles before configuration articles.

When we changed the value in WCF service configuration, it didn't help, because the similar change must be ALSO done on client.

There are similar posts:

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

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

It seems that DataContractJsonSerializer.MaxItemsInObjectGraph has actual default 65536, because there is no configuration for JSON serializer, but  it complains about the limit.

I believe that MS should clarify the properties documentation re default limit and make more specific error messages to distinguish server side and client side errors.

Note, that as a workaround it's possible to use commonBehaviors section which can be defined only in machine.config:
<dataContractSerializer maxItemsInObjectGraph="..." />

Posted on Sunday, October 28, 2012 1:02 PM Web Services/WCF | Back to top

Comments on this post: maxItemsInObjectGraph limit required to be changed for server and client

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Michael Freidgeim | Powered by: