Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader

I'm getting the following exception while sending ( or receiving ) a byte array to a C# service.

There was an error deserializing the object of type System.Byte[]. 
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 6, position 34838.'.  
Please see InnerException for more details

For what I can understand the XmlDictionaryreader is created automatically by the webservice.

So, how can I change the "MaxArrayLength" property?

This is the implementation code:

    public string addFile(string sharePointServer, string documentLibrary, 
                          byte[] content, string fileName) 
    {
        try
        {
            SPWeb spWeb = new SPSite(sharePointServer).OpenWeb();
            SPFolder spFolder = spWeb.GetFolder(documentLibrary);
            SPFileCollection spFileCollection = spFolder.Files;
            SPFile spFile = spFileCollection.Add(fileName, content, true);
            return spFile.TimeCreated.ToLongDateString() + "::" + spFile.Title;
        } 
            catch (Exception ex) 
        {
            throw ex;
        }
    }

Files < 16kb are uploaded.

Files > 16kb are not.

Files > 10mb are downloaded without problem.

Where is that property configured?

like image 380
OscarRyz Avatar asked Nov 18 '25 00:11

OscarRyz


2 Answers

Is it a WCF service? If so, you can change the maxarraylength in the binding as seen on this SO post:

post

P.S. Why would you use a custom Service when there are OOTB Sharepoint services that can upload files? i.e. the Lists.asmx like in this article:

article

like image 196
Colin Avatar answered Nov 19 '25 15:11

Colin


Add a <readerQuotas> element inside the <binding> element and add MaxArrayLength property

 <bindings>
     <wsHttpBinding>
         <binding name ="Your WSHttpBinding Name" sendTimeout="00:05:00" maxReceivedMessageSize="2147483647">
             <security mode="None"></security>
             <readerQuotas maxStringContentLength="134217728" maxArrayLength="2147483647" />
             <reliableSession enabled="true"/>
         </binding>
     </wsHttpBinding>
 </bindings>
like image 42
BigBoss Avatar answered Nov 19 '25 14:11

BigBoss



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!