Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Can't catch exceptions from HttpWebRequest after Xamarin update

MarkJensenMarkJensen USMember ✭✭
edited October 2018 in Xamarin.Forms

Hi,

I had already asked this question before, but it seems like my post got lost for some reason.

After I updated everything, Xamarin, Xamarin.iOS, etc. my app has started crashing for my users (I still use Xamarin Forms 3.1). It seems to be a problem in Mono with the httpclient implementation.

I sometimes get this exception:

 HttpWebRequest+<MyGetResponseAsync>d__243.MoveNext()
android.runtime.JavaProxyThrowable: System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.Net.WebException: The request was aborted: The request was canceled. 

I have try catch around my code, but for some reason, it doesn't get caught. It used to work fine, but after the update, it stopped working. I've tried to use an older version of mono, but I'm not sure how far back I have to go.

Does anyone have the same problem and perhaps a solution?

Answers

  • MarkJensenMarkJensen USMember ✭✭

    It seems like the app doesn't actually crash, but we still get reports from HockeyApp as if it crashed.

  • JohnHardmanJohnHardman GBUniversity admin

    @MarkJensen - Post the code of the method where you make the HTTP request, and the code of MyGetResponseAsync

  • VfWesVfWes USUniversity ✭✭

    We are seeing the same errors for Xamarin Forms in iOS.

    All of our http calls are "safe" in that they are wrapped in try-catch. But this exception occurs, somehow bubbles all the way up, and crashes our app. We use modernhttpclient for requests we expect to last under a minute, but some of our web requests will take longer and therefore we use HttpClient for those calls (modernhttpclient will not honor a timeout value greater than 1 minute). It appears to be happening only when we use the standard HttpClient.

    We are on an older version of Xamarin Forms than you are and still have the issue.

    **Stacktrace:
    **
    {System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.Net.WebException: The request was aborted: The request was canceled.
    at System.Net.HttpWebRequest+d__243.MoveNext () [0x003d5] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.13/src/Xamarin.iOS/mcs/class/System/System.Net/HttpWebRequest.cs:1032
    --- End of inner exception stack trace ---
    ---> (Inner Exception #0) System.Net.WebException: The request was aborted: The request was canceled.
    at System.Net.HttpWebRequest+d__243.MoveNext () [0x003d5] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.13/src/Xamarin.iOS/mcs/class/System/System.Net/HttpWebRequest.cs:1032 <---
    }

  • VfWesVfWes USUniversity ✭✭

    4.6.0.299 is the last version that worked for us.

    Some devs had 4.6.3.4 and it has the issue you have described. We had those devs update to the latest stable version (4.8.0.756) to see if it was fixed in that time, and it seems like it is not.

    Interestingly it seems that exception has been a problem for a while as there is an old bugzilla post about it from 2014. The status is resolved fixed but looks like it regressed at some point after 4.6.0.299 (we are scrambling to find a good version that's newer than 4.6 from August of last year)

    https://bugzilla.xamarin.com/show_bug.cgi?id=19913

Sign In or Register to comment.