Visual Studio 2010/C# 4.0, WCF, NHibernate, Silverlight 4
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.’.
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>