3

I am developing a Xamarin.Forms (4.1.0) app, which makes REST calls.

When calling my web service, the application crashes, with no exception.

Only got this message on the output:

07-08 19:09:04.792 F/        (22723): * Assertion at /Users/builder/jenkins/workspace/xamarin-android-d16-1/xamarin-android/external/mono/mono/mini/debugger-agent.c:4387, condition `is_ok (error)' not met, function:get_this_async_id, Could not execute the method because the containing type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[RestQueryResultT_REF]', is not fully instantiated. assembly:<unknown assembly> type:<unknown type> member:(null)
07-08 19:09:04.793 F/libc    (22723): Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 22723 (io.puffix), pid 22723 (io.puffix)

Here is the code:

RestQueryResultT queryResult;

using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(serviceUri))
{
    string result = await response.Content.ReadAsStringAsync();
    queryResult = ParseResult(result);
}

return queryResult;

The call is made from an event handler method, fired by a UI action. The GetAsync call made tha app crashes.

Any idea to solve this issue ?

7
  • which line causes the crash? Have you tried catching the exception? Commented Jul 8, 2019 at 17:19
  • The GetAsync line cause the crash. Yes, tried to add catch, and suscribed to errors from the App, with no success. Commented Jul 8, 2019 at 17:21
  • does it only crash on Android? Have you tried switching the HTTP stack? Do you have Internet permissions enabled? Have you tested that your url is accesible from the device/emulator using the browser? Commented Jul 8, 2019 at 17:29
  • I am developping only on Android. The internet permissions are enabled. The URL is browsable from my device. How can I switch the HTTP Stack ? Commented Jul 8, 2019 at 18:19
  • learn.microsoft.com/en-us/xamarin/android/app-fundamentals/… Commented Jul 8, 2019 at 18:21

2 Answers 2

16

This seems a issue and already filed in the Github. You can see the discussions in these threads:

  1. await within method with returntype Task makes app crash
  2. xamarin-android/issues
  3. xamarin-ios/issues

The workaround is using GetAwaiter().GetResult() instead of await:

Works:

response = _client.GetAsync(uri).GetAwaiter().GetResult();

Does not work:

await _client.GetAsync(uri);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks... This is pathetic ! The problem has been there for a long time and not fixed yet !
this helped me too - been scratching my head at this for awhile. how is this still an issue?!
1

could you try with a smaller response? I had the same problem (in my case, when I tested with 2 or 3 records from the server, it worked fine, but if I used 10 records, it crashed). I had to change the simulator. I am using now my real phone connected to my computer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.