Forum Xamarin.Forms

NameResolutionFailure vs ConnectFailure issue

JordanMaxJordanMax USMember ✭✭
edited October 2016 in Xamarin.Forms

So a rather peculiar issue, but a pretty bad one nonetheless. When a user enters our app with no internet at all, we get back a NameResolutionFailure as the error message for trying to make a API call via HttpClient. Okay, that's fine. The issue though is, when the user then connects to internet, goes back to app, and attempts to make another API call, we get the same error message. It appears that some kind of DNS caching is happening?

On the flip side, if a user HAS internet access while in app, then loses it, when we try to make an API call we get aConnectFailure(Network is unreachable)error from the API call. And as soon as the user connects to the internet, they can make API calls instantenously.

The issue I'm trying to figure out is, A) What's the difference between NameResolutionFailure and ConnectFailure ? and B ) Is there anything we can do in app to force it to completely retry the API call without using any cache? It's not obvious to me if the DNS is being cached or not, but we have a hinting feeling that's what's happening.

Here's part of the code (if you need more let me know, I figured this is the only code needed)

using(var client = new HttpClient()) { client.Timeout = TimeSpan.FromSeconds(MaximumWebRequestTime); HttpResponseMessage response = null; try { response = await client.GetAsync(URL); if (response.IsSuccessStatusCode) ....

Best Answer

Answers

  • AliakseiAliaksei USMember

    We observe the same problem, but without Xamarin.Forms. Switching of DNS cache in HttpClient didn't help.

    Reproducible in both iOS 10 and 9.

  • JordanMaxJordanMax USMember ✭✭
    edited October 2016

    I posted this same question on stack overflow (link: http://stackoverflow.com/questions/40137190/nameresolutionfailure-vs-connectfailure-issue/40139147#40139147), and did get somewhat of an interesting response, from someone who says they are a MS/Xamarin support engineer. He mentioned he had this problem while in airplane mode initially, and then turning it back on he had the same issue I (and Aliaksei) have. But if he went into app with no airplane mode, turned it on, and then turned it off, was able to connect successfully. (although he's saying this is a Xamarin.Android issue, when clearly it is not. He did say a workaround was regressing to a earlier Android version, not sure if that would help iOS. I'm currently on Xamarin 4.2.0.680 and Xamarin iOS 10.0.0.6. I have not tried an earlier version for the fear of it breaking my app) He linked me to a bugzilla post he made, here's the link:

    http://bugzilla.xamarin.com/show_bug.cgi?id=45383

    This is a pretty aggravating issue, and I would really like to know if there's any workaround. I feel like this is a pretty basic thing.

  • NMackayNMackay GBInsider, University mod

    @JordanMax

    Thanks for posting the bugzilla, I can confirm I've seen this issue too on more than one occasion due to the office wifi been so bad.

  • NMackayNMackay GBInsider, University mod

    @Theos said:
    Setting the DNS refresh timeout helped me to temporary solve this problem, see:
    http://stackoverflow.com/a/40725278/1560797

    Thanks for this, worth mentioning it won't work for UWP as ServicePointManager doesn't exist.

  • TheosTheos NLBeta ✭✭

    @NMackay said:

    @Theos said:
    Setting the DNS refresh timeout helped me to temporary solve this problem, see:
    http://stackoverflow.com/a/40725278/1560797

    Thanks for this, worth mentioning it won't work for UWP as ServicePointManager doesn't exist.

    Oke good to know. But as far as I read the issue is a Mono issue, so UWP should not have this problem.
    Haven't checked it yet on my UWP app.

  • JordanMaxJordanMax USMember ✭✭

    I can verify that Theos' solution works on Xamarin.

  • Well, I can't verify that it works, it doesn't

    • I am consuming a REST service in a PCL library (Android project) and I get a name resolution failure, service deployed on local IIS (not IISExpress)
    • Consuming the service works when I type the url in my browser
    • It also works consuming it from a Winforms project
    • And it works from both the PCL and the Winforms project when I use the Url to an Azure url

    So I can continue developing, but it is a pain in the neck having to use Azure all the time. I am very surprised that this is not solved in the latest release

  • I have found a solution that works for me: instead of resolving the local IIS name, I am using the local IP
    Now I can work with both Azure and local IIS :-)

  • JordanMaxJordanMax USMember ✭✭
    edited March 2017

    @JeroenvanVlierden said:
    Well, I can't verify that it works, it doesn't

    • I am consuming a REST service in a PCL library (Android project) and I get a name resolution failure, service deployed on local IIS (not IISExpress)
    • Consuming the service works when I type the url in my browser
    • It also works consuming it from a Winforms project
    • And it works from both the PCL and the Winforms project when I use the Url to an Azure url

    So I can continue developing, but it is a pain in the neck having to use Azure all the time. I am very surprised that this is not solved in the latest release

    Well it does work with the problem I had, looks like your issue is different.

Sign In or Register to comment.