0
votes

I am using the below code snippet:

public async Task<LoginUser[]> GetUserAsync()
{
    var client = new System.Net.Http.HttpClient();
    client.BaseAddress = 
        new Uri("http://developer-platform.com/dutyfreebuzz/web_services/Login");
    StringContent str = new StringContent("username=admin&password=12345", Encoding.UTF8, "application/x-www-form-urlencoded");
    var response = await client.PostAsync(new Uri("http://developer-platform.com/dutyfreebuzz/web_services/Login/loginJSON"), str);
    var loginJson = await response.Content.ReadAsStringAsync();
    Rootobject rootobject = new Rootobject();
    if (loginJson != "")
    {
        //rootobject = JsonConvert.DeserializeObject<Rootobject>(loginJson);
    }
    //return rootobject.loginusers;
}

I have set the breakpoint to this function. During execution, the debugger is not moving to PostAsync call and it is moving out of the function.

1
There is a currently known issue with setting breakpoints in async/await code in portable class libraries if the linker is enabled on iOS: developer.xamarin.com/releases/vs/xamarin.vs_4/xamarin.vs_4.1 So you might be hitting this. There is a workaround where you disable linking for your iOS project. Are you maybe hitting that?Cheesebaron
@Cheesebaron: Yes, I have linked to IOS. So how should I check for the response. I am developing using xamarin studio on my mac machine.Himanshu Dwivedi
You could print out to the console. Also I don't think you need to set BaseAddress if you are using the full URL in PostAsync. However, I don't think that is the issue.Cheesebaron
@ Cheesebaron: I solved the issue by setting a breakpoint on the response line code. But is takes a few minute for debugger to catch. Yes, I don't need the BaseAddress by mistake I forgot to comment.Himanshu Dwivedi
@Cheesebaron - I have summarized the answer you have provided in the comments, if there is anythin furhter to add please Edit or update.Rohit Vipin Mathews

1 Answers

0
votes

This answer is a summary of comments by Cheesebaron and OP, as the solution was provided in the comments.

There is a currently known issue with setting breakpoints in async/await code in portable class libraries if the linker is enabled on iOS.

41836: For iOS apps, breakpoints within async methods in PCL projects are not hit if the linker is enabled. Partial temporary workaround: Set Project Properties > iOS Build > Linker behavior to Don't link. (For device builds this workaround does unfortunately create significantly larger .app bundles and can lengthen deployment times.)

As a work around set the break point in the WriteLine():

System.Diagnostics.Debug.WriteLine(response);