Communicating using httpclient

SamWhelanSamWhelan USMember
edited August 2014 in Xamarin.Android

Hi, I have been attempting to retrieve data from my OData Service (the result of which I can see by hitting the url directly). I have accomplished this with ease in a console application (Visual Studio).

After following various tutorials including the ones on the developer section of this site, I have yet to achieve a working solution.

I have also attempted to create a basic application to call for a simple http response, however, as soon as the program makes the call, the application hangs before becoming unresponsive and failing to hit any further breakpoints.

The result in the application output always ends with:
[Mono] DllImport attempting to load: '/system/lib/'. [Mono] DllImport loaded library '/system/lib/'. [Mono] DllImport searching in: '/system/lib/' ('/system/lib/'). [Mono] Searching for 'gettid'. [Mono] Probing 'gettid'. [Mono] Found as 'gettid'.

Here is the code:

Any ideas as to why this might be?


  • CheesebaronCheesebaron DKInsider, University mod

    Try adding .ConfigureAwait(false) to your Task. However it is really nasty to create something async just to call it synchronously...

  • SamWhelanSamWhelan USMember
    edited August 2014

    Thanks for the reply.
    I tried adding newTask.ConfigureAwait (false); after creating the task, but the application still freezes after the call is made.
    (This happens at the line
    return await hc.GetAsync (uri.ToString());)

    Here is a link to the modified code

  • CheesebaronCheesebaron DKInsider, University mod

    Add it to the GetAsync method as well.

  • SamWhelanSamWhelan USMember
    edited August 2014

    Sorry, which line am I supposed to add it in that case?
    like this?

    'return await (hc.GetAsync (uri.ToString())).ConfigureAwait(false);'

    Thanks, got it working.

  • SamWhelanSamWhelan USMember

    Ok, so I got it working with the http request, so I tried to copy the methodology over to my OData test program.
    Would you mind having a look to see if you can spot anything obvious, as it still freezes when using OData as opposed to http.

  • CheesebaronCheesebaron DKInsider, University mod

    It is in general bad practice to call async methods in constructors and in void methods. You should really avoid that.

    Stephen Cleary has some nice blog posts about Async OOP: read the posts, they are really informative.

Sign In or Register to comment.