Software Architecture – Exception -MaxArrayLength property on the XmlDictionaryReaderQuotas object

Environment:
Visual Studio 2010/C# 4.0, WCF, NHibernate, Silverlight 4
Exception:
While uploading a file by converting file content into array of bytes and sending it to server side via WCF, generates following exception.

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:***. The InnerException message was ‘There was an error deserializing the object of type ****. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 57216.’.

Solution:
If you search XmlDictionaryReaderQuotas in object browser, you will find as:



So there is a configuration option in Servicemodel configuration, for setting the maximum array size limit. You can change the default limit of maxArrayLength tag by adding following XML in Service configuration of WCF Service as:

<bindings>
        <basicHttpBinding>
          <binding
                   maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="0:50:0" openTimeout="0:50:0" receiveTimeout="0:50:0" sendTimeout="0:50:0"                  
                   >
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2097152"  maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          </binding>

          </basicHttpBinding>
</bindings>

Reference:
http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding.readerquotas.aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: