So I posted about this earlier where ReadToEnd will throw an exception
randomly and rather rare, but it is indeed happening.  It happened last
night, and nothing is logged to LogCat, absolutely nothing.  As you can see
in the code below I have this wrapped in a Try/Catch but it doesn't matter,
the entire app is killed when this occurs which makes me think it is on the
Java side of the house.  

Can someone take a look at this particular piece to see if something can be
done to make this a bit safer?  It kills the entire app when the exception
occurs, I do not know what causes the exception it occurs randomly.  I have
used my app for hours and hours with no problem, and it may just happen
randomly once with no recognizable pattern.  Perhaps the connection is
terminated prematurely at some point and causes this to throw an exception?
I have no idea as I only get this behavior on Mono Droid and not in my Unit
Testing project which uses .NET, or at least I think since its so rare it
may occur in both I have just never caught it in a Unit Test...

  private static void MakeGetRequest(EventHandler<OAuthEventArgs> callback,
HttpWebRequest request)
        {
            request.BeginGetResponse(asyncRes =>
            {
                HttpWebResponse response = null;
                try
                {
                    //request has returned
                    response =
(HttpWebResponse)request.EndGetResponse(asyncRes);
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        using (StreamReader sr = new
StreamReader(response.GetResponseStream()))
                        {
                            var token = sr.ReadToEnd();
                            callback(null,
                            new OAuthEventArgs() { Response = token });
                        }
                    }
                }
                catch (WebException we)
                {
                    string t = new
StreamReader(we.Response.GetResponseStream()).ReadToEnd();
                    callback(null, new OAuthEventArgs() { Error = we,
ErrorMessage = t, IsError = true });
                }
                catch (Exception e)
                {
                    callback(null, new OAuthEventArgs() { Error = e,
ErrorMessage = e.Message, IsError = true });
                }
                finally
                {
                    if (response != null)
                        response.Close();
                }
            }, null);
        }

--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/GetResponseStream-ReadToEnd-Fatal-Exception-tp5627778p5627778.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to