Forum Xamarin.iOS


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Timeout exception HttpWebRequest.GetResponse() in Mono 5.X

I realize this might not be the best place to post an issue with Mono, but I'll do it in case someone encountered a similar issue.

I have this code:

string apiUrl = "";

System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(apiUrl);
webRequest.ContentType = "text/json";
webRequest.Accept = "Accept-application/json";
webRequest.Method = "GET";
webRequest.Headers.Add("tokenId", "00000000-0000-0000-0000-000000000000");

webRequest.AutomaticDecompression = System.Net.DecompressionMethods.Deflate | System.Net.DecompressionMethods.GZip;
webRequest.CookieContainer = new System.Net.CookieContainer();
webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;

    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)webRequest.GetResponse();

catch (Exception ex)

Prior to Mono 5.X, this has worked fine and returned with the response without much issue. Since Mono 5.0 and later, this has stopped working and instead throw a Timeout on GetResponse consistently. I've been building my release with Mono 4.8.1 for a few months because of this issue, but building the UnifiedAPI version with the static registrar with Xamarin Studio and Mono 4.8.1 fails.

I don't think this is an issue with HttpWebRequest per se. But with the Mono implementation and maybe the server I'm connecting to? That being said, there is definitely something different regarding the HttpWebRequest between Mono 4.8.1 and 5.0.

Any ideas?

I'll keep investigating and if I find anything more concrete, I'll file a bug.


  • XavierFortinXavierFortin USMember ✭✭

    I'm adding a bit more information on this after investigating.

    I'm pretty sure the timeout happens only on some HTTPS server. In fact, my issue seems very similar to this one from two years ago.

    I've tested with NSURLSession and I have no issue with it, so this is definitely Mono related.

    I know of some of our users who experienced the issue before downgrading to Mono 4.8.1 and I have one internal server on which I can reproduce this. But since I don't know what's special about the faulty service, I can't reproduce this into a test Web Service. I tried. Maybe something weird with the certificate?

    I'm pretty sure this has to do with the SSL negociation. If I configure a proxy between my application and the remote server, and I enable the HTTPS traffic decryption (in this case I use Fiddler on a VM), it suddenly starts to work without issue.

    I know I'm not being particularly helpful here, but I'm kind of desperate.

    I'm working on using NSURLSession instead, but that could prove to be quite a task.

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    So try building / running with MONO_TLS_PROVIDER=legacy in newer (but not latest) Xamarin.Mac.


    and compare to the default of AppleTLS.

    AppleTLS has some behavior changes from the old legacy TLS, maybe you are hitting one of those?

  • XavierFortinXavierFortin USMember ✭✭

    I get the same behavior in Xamarin.Mac 3.0 and 3.2 with or without MONO_TLS_PROVIDER set to legacy.

    I'm following the instruction found in the Mono 5.0.0 release notes:

    Is setting the MONO_TLS_PROVIDER environment variable all that is needed?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    So MONO_TLS_PROVIDER will in theory let you swap the tls provider (and determine if this is introduced by that). The rub however, is this:

    we define that for both supported profiles:


    since legacy TLS is not something we want to support in XM supported profiles.

    Doing some more digging, this was introduced 2017-02, so any Xamarin.Mac after 3.2 won't honor MONO_TLS_PROVIDER.

    However, if your test is a simple console application, not using Xamarin.Mac, then you can install various mono's to determine when the behavior change occurred. It is not clear for your post if your sample requires XM or can be done in a console app.

  • XavierFortinXavierFortin USMember ✭✭

    I did produce the bug in a Mono console app. Just to be sure, I've went back an tried with the Mono 4.8.1 and 5.0.0. I can confirm that this started in 5.0.0.

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Please file a bug with your sample app attached and I'll get it directed to the right team.

  • XavierFortinXavierFortin USMember ✭✭

    Sure can do.

    Here it is:

    I can't provide a functioning test project though. I'm testing on a local server and, as mentioned, I don't know what's special about it as other similar servers do not have the issue.

    Another thing I'd like to mentioned. I don't know how I haven't noticed it sooner (I think it might be because of the recent updates). Most HttpWebRequest do not work anymore. At least, all those I've tested so far have timed out. This only seems to be in the Classic API though. While it's not much of an issue since I'm migrating to the Unified API, maybe it's somehow related to my main issue?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Classic XM uses the system mono very directly, so any issue you have with console applications would directly hit it. Unified builds it own curated version of the BCL / runtime for storage internally, so doesn't touch system mono (whatever version you have) outside of using tooling.

Sign In or Register to comment.