locked
Index out of range exception when calling HttpWebRequest.BeginGetResponse RRS feed

  • General discussion

  • Hi

    I'm using Silverlight 2 beta 2.

    The following chain of events will cause an index out of range exception to be thrown.

    - call HttpWebRequest.EndGetRequestStream in a using statement

    - exit the using statement without writing to the stream

    - call HttpWebRequest.BeginGetResponse

    Sunday, July 6, 2008 12:00 AM

All replies

  • Well of course it does; you haven't put anything in the stream, so the first attempt to get anything back will fail.

    Sunday, July 6, 2008 9:46 AM
  • Hi

    I didn't properly explain my point.

    I was expecting one of two outcomes.

    1) No exception is thrown

    2) A relevant exception is thrown. For example, System.Net.WebException with a message something like "Input stream is empty". The index out range exception is very confusing and, in my opinion, will cause problems for other developers.

    I encountered the error because I had the following code in an abstract class:

    using (Stream stream = httpAsyncRequestWrapper.FetchStream(asyncResult))
    {
        this.WriteToStream(stream);
    }

    The WriteToStream method is abstract.

    Thanks

     

     

     

     

    Monday, July 7, 2008 11:34 AM