Bug 42471 - client.PostAsync returns immediately in Xamarin.Forms iOS app ( 3cf8aae)
Summary: client.PostAsync returns immediately in Xamarin.Forms iOS app ( 3cf8aae)
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: XI 9.8 (tvOS / C7)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2016-07-11 21:43 UTC by faceoffers28
Modified: 2016-09-15 10:09 UTC (History)
7 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description faceoffers28 2016-07-11 21:43:22 UTC
I just moved my Project over to Visual Studio 2013 Premium Update 5, running on Windows 10. In doing so, I configured the Xamarin Mac Agent. After fixing SEVERAL issues, I've found one issue that appears to be a bug.

This line of code runs and then immediately returns.

HttpResponseMessage response = client.PostAsync(Urls.Auth, contentPost).Result;

The app doesn't crash and continues to run. It doesn't execute the code underneath it, but executes the next method.

Here is  my config.

Xamarin (34a92cd)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android (7db2aac)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS (3cf8aae)
Visual Studio extension to enable development for Xamarin.iOS.
The line of code in question is in a Portable Project that contains all my REST API call logic. My Android app works just fine, so it has something to do with the iOS app. The iOS app worked just fine on my Mac running Xamarin Studio 5.10.3, so I know there is nothing wrong with the code.
Comment 1 faceoffers28 2016-07-11 22:34:21 UTC
My apologies. I need to make a correction in my original statement.

The following line doesn't return. It just stops. It behaves like a deadlock in my Xamarin.Forms iOS app.

HttpResponseMessage response = client.PostAsync(Urls.Auth, contentPost).Result;

If I make the calling method async and add an await statement (see below), the line of code runs, but immediately skips the next lines of code and continues with the next method.

HttpResponseMessage response = await client.PostAsync(Urls.Auth, contentPost);
Comment 2 John Miller [MSFT] 2016-07-15 15:29:27 UTC
> HttpResponseMessage response = client.PostAsync(Urls.Auth, contentPost).Result;

This will appear to hang the UI. Take a look here for some explanation: http://stackoverflow.com/a/17248813/1454417

> HttpResponseMessage response = await client.PostAsync(Urls.Auth, contentPost);
> but immediately skips the next lines of code and continues with the next method.

This sounds like expected behavior for an await call. When you hit an await, control returns to the calling method and execution could continue. Hopefully you have an async, Task-returning method calling this. If it's async void (not an event handler) then there could be some issues going on that are unexpected. Once PostAsync finishes it's work, it will return back after the await an execution would continue in that method. Place a breakpoint on the line after the await to easily see this. 

If you still have an issue, please attach a sample that I can run to reproduce this. Thanks!
Comment 3 faceoffers28 2016-07-15 16:00:49 UTC
John, thanks for the response. Please see the last statement in my original entry. This was working in my iOS app and it still works in my Android app. The only things that have changed is that I have moved my project over to Windows 10 and I have upgraded Xamarin.iOS.
Comment 4 John Miller [MSFT] 2016-07-15 16:02:51 UTC
Is "Urls.Auth" an IP address instead of a domain name?
Comment 5 faceoffers28 2016-07-15 16:51:39 UTC
Nope, it consists of a BaseUrl that is an HTTPS link to the API. It also includes an Auth parameter the combines the BaseUrl with the extension in order to complete the Authorization URL. The Auth endpoint generates and retrieves a token. Without the token, I can't make subsequent requests.
Comment 6 faceoffers28 2016-07-16 23:56:06 UTC
In order to solve this issue and Build my app using the Xamarin Mac Agent, I had to downgrade both my Mac and my Windows 10 machine to the "Stable Release: Cycle 6 Service Release 3" versions of all packages found here.

Comment 7 Rui Marinho 2016-08-11 17:16:45 UTC
Ok seems it wasn't a Xamarin Forms issue. 

Comment 8 John Miller [MSFT] 2016-08-11 18:04:47 UTC
Reopened and moved to iOS because it seems there might be an issue here if downgrading "fixed" it. If anyone has a sample project that can be used to reproduce this, please attach to the bug.
Comment 9 Marek Safar 2016-08-17 07:37:58 UTC
Waiting on any information how to reproduce it
Comment 10 Manuel de la Peña [MSFT] 2016-09-15 10:09:57 UTC

We have not received the requested information. If you are still 
experiencing this issue please provide all the requested information 
and re-open the bug report. Thanks!