xml - Why is MemoryStream limited to 6KB of data? -


i have xml document, 7,917 characters. it's read xelement using linq xml, need map/convert/adapt xelement string (to send web service).

here method:

    public string adaptxelementtostring(xelement xml)     {         encoding encoding = encoding.getencoding(specializedencodings.iso88591);          using (memorystream memorystream = new memorystream())         {             xmlwritersettings settings = new xmlwritersettings { encoding = encoding };              memorystream.setlength(21*1024*1024);              using (xmlwriter writer = xmlwriter.create(memorystream, settings))             {                 xml.writeto(writer);                 memorystream.flush();                  string xmltext = encoding.getstring(memorystream.toarray());                 return xmltext;             }         }     } 

when call method, can see using intellisense 'xml' has entire contents of file. however, string xmltext gets chopped off @ 6144th character (which 6 kb exactly). because xmltext getting chopping off, i'm losing 1773 characters.

does know why method isn't returning entire string? set length of memory stream buffer 21 mb ensure it's big enough (even though default constructor supports resizing).

i same behavior if remove call setlength(). same behavior if remove call flush().

for purposes, must use encoding iso-8859-1, can't change utf-8 or 16.

any appreciated!

solved problem:

use writer.flush(); not memorystream.flush()


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -