none
StringBuilder OutofMemory Exception RRS feed

  • Question

  • Hi,

    Through web service i try to read large amount of data.

    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri);
                            request.ContentLength = 0;
                            request.Method = "GET";
                            request.KeepAlive = true;
                            request.Timeout = Timeout.Infinite;
                            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                            {

    using(Stream dataStream = response.GetResponseStream())

    {

    Using (Streamreader Sreader = new StreamReader(dataStream))

    {

    StringBuilder sb = new StringBuilder();

    sb.Append(Sreader.ReadToEnd()); //  Throws Out Of memory Exception

    }

    }

    }

    When i try to read buffered data from Webservice I can't get the Length. (System.NotSupportedException)

    Windows Mobile 6.5 development , Framework 3.5 , C#


    Aneesh S


    Friday, September 26, 2014 3:28 AM

All replies

  • Maybe you have to read and immediately process smaller fragments, for example with a series of Sreader.ReadLine.

    Have you checked if the exception is caused by ReadToEnd or by Append?

    • Edited by Viorel_MVP Friday, September 26, 2014 5:39 AM
    Friday, September 26, 2014 5:38 AM