Reputation: 3301
I'm new to this, so please bear with me. I am debugging and having an issue with the line:
var response = await client.GetAsync(uri);
I've edited the question so it complies with a Minimal, Complete, and Verifiable example.
I step-over the debugger on this statement so to move at the next statement but for reason still unknown to me, debugger seems to lost and does not recover.
Every time I hit the await
call and step-over, it just happens every time. The debugger breakpoint just disappears.
Following is all the code:
public class App : Application // superclass new in 1.3
{
public App ()
{
MainPage = new PinPage { Title = "Pins", Icon = "marker.png" };
}
}
public class PinPage : ContentPage
{
private async Task FetchDataAsync()
{
HttpClient client = new HttpClient();
string resultUrl = "http://myuser.gtempurl.com/Service1.svc/GetLocations";
var uri = new Uri(string.Format(resultUrl, string.Empty));
var response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
string content = await response.Content.ReadAsStringAsync();
var obj = JsonConvert.DeserializeObject(content);
}
}
public PinPage ()
{
FetchDataAsync().GetAwaiter().GetResult();
}
}
The WCF service is not the issue. It is published in a public server, so it is always available. I call it from a browser and it returns the expected string.
I am using VS2017 and it debugs in an Android Emulator.
Here is a screen capture of when breakpoint hits the statement:
Upvotes: 2
Views: 2089
Reputation: 456887
it does not move to the next line. No other line of code is highlighted yellow, no timeout, nothing.
This sounds like a deadlock. Since this is a UI application, check further up your call stack for any blocking calls like Wait()
, Result
, or GetAwaiter().GetResult()
. These can deadlock if called from the UI thread.
The proper solution is to change them to await
; in other words, use async
all the way.
Upvotes: 7
Reputation: 2668
Use Postman (https://www.getpostman.com/) test the URL firstly. If postman can get data, there is something wrong with you client app. Otherwise, the web api is not working.
Upvotes: -1
Reputation: 1298
Await operator works this way , when you await a task the code execution will jump out of the current function and yield control to its caller. Then when the awaited Task finishes, it will jump back to execute code after the await statement.
In your case : The await operator suspends execution until the work of the "client.GetAsync(uri) " method is complete. In the meantime, control is returned to the caller of FetchDataAsync. When the task finishes execution, the await expression evaluates to a response.
If you step over after the await has evaluated the response , the debugger will navigate to the next step , If the await has not returned the debugger's highlight is lost.
Upvotes: 0