System.Net.WebException Error: NameResolutionFailure

I periodically get this exception thrown from an android app I am writing side by side with an iOS application. At first, I thought it was a problem with my service being down but, I no longer think this is the case (I never un into the exception in iOS and it is running the EXACT same code). It may or may not matter, but this is running on a Nexus 4 with Android 4.3.

Any ideas as to why this error would happen, and why it would be random?

The stack trace looks like this...

{System.Net.WebException: Error: NameResolutionFailure
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.0-branch/b76e8ec4/source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:945
at IMI.Webstore.Mobile.Core.RestClient.WebRequestExtensions.GetResponse (System.Net.WebRequest request) [0x00033] in c:\Users\jkrebs\code\3Wire\WebStore-Main\WebStoreMobile\Common\IMI.Webstore.Mobile.Core\RestClient\WebRequestExtensions.cs:23
at IMI.Webstore.Mobile.Core.RestClient.RestClient.MakeRequestSynchronous[Part] (System.String requestUrl, System.String verb, System.Object bodyContent) [0x00071] in c:\Users\jkrebs\code\3Wire\WebStore-Main\WebStoreMobile\Common\IMI.Webstore.Mobile.Core\RestClient\RestClient.cs:107 }



  • CheesebaronCheesebaron DKInsider, University mod

    Did you give your app the correct permissions?

  • JoshuaKrebsJoshuaKrebs USMember

    Yeap I did, Most requests work just fine, just periodically, only on Android 4.3, I get that exception... Any other ideas?

  • CheesebaronCheesebaron DKInsider, University mod

    Not sure at all. I doubt using HttpClient will change anything, but maybe worth a try.

  • ForceMagicForceMagic USMember ✭✭

    If Joshua Krebs is in the same situation than me, he uses the Portable Class Library (PCL) to write common code between both iOS and Android version. In that case, the HttpClient is not supported by PCL.

    It's pretty much my problem as well, I get this NameResolutionFailure intermittently on a local server in my company. I also already added the proper permissions.

    Any suggestions? or anyone else with that problem?

  • @ForgeMagic this is indeed the same situation I am in... :(

  • rmaciasrmacias USBeta, University ✭✭✭✭✭

    So you're running on a Nexus 4 with Android 4.3? Does this happen with WiFi only, or does it happen over cellular too? The Nexus 4 is know to have issues with WiFi that was introduced with Android 4.3. Perhaps the wifi is just flaking out. Have you tried on another device, or maybe downgrade your device to Android 4.2?

  • ForceMagicForceMagic USMember ✭✭
    edited September 2013

    @rmacias I forgot to mention, in my case I am using a Nexus 7 on Android 4.3 as well. Kernel version 3.1.10-g1e8b3d8.

    I am on the Wifi, but since it's intermittent the same call will pass on the first execution and can fail later on when called again.

    EDIT: Although by reading through more of the post you have sent, it seems that the Nexus 7 also holds the problem. Hopefully that will be fixed soon. This is really annoying.

  • JoshuaKrebsJoshuaKrebs USMember
    edited September 2013

    Not to post on an older thread (I've been ignoring this issue for a bit now) I am still having the issue occasionally on the nexus 4 but haven't yet been able to isolate it to Wifi, I do know for certain though, that pre-upgrade it worked perfectly which would lead me to believe it could be the wifi issue. I do MOST of my dev over wifi maybe I will try over cell network for a while and see if it helps.

    I could easily downgrade my version of android, but I don't have control over the users of the app I'm developing and it would be a shame to say they can't upgrade if they want to use the app.

  • jamie94bcjamie94bc GBMember
    edited October 2013

    I'm having the same issue on Android 4.2.1 (and it seems this guy does too:

    I'll see if another emulator/device makes any difference.

    Does using System.Net.Http.HttpClient fix this?

    Turned out to be an issue with our office's network - glad I spent an hour or so chasing that.

  • ForceMagicForceMagic USMember ✭✭

    The best solution I found, when that exception occurs while the Wifi is connected, is just to retry my server call with a slight sleep in between. It works most of the time, otherwise if the second call fails I cancel the request.

    This error can also raise if the user's Wifi is very unstable or the signal is very low. The same error occurs if there is no internet connection at all, even if connected to Wifi.

    In any cases, I show a case per case message to the user.

  • @ForceMagic - I only get it when connected to WiFi too. My office is at the outer edge of WiFi coverage so my phone has an unstable connection at times.

    Retrying doesn't seem to be a good option for me. I've tried programmatically switching WiFi off and on, but that's too slow and is probably way out of bounds in terms of UX.

  • DaveCarsonDaveCarson GBUniversity ✭✭✭

    Just ran up against this and I can't believe that it worked with mobile network but not with WiFi! Frankly that's just insane!

  • For me Its works in 4.2 or lower. But in 4.3 or 4.4 the first call to rest service using HttpWebRequest is working fine and the subsequent requests are failing. Any solution to overcome this?

  • AndrewArnottAndrewArnott USMember ✭✭

    I'm having the same problem. Nexus 4, over WiFi. I'm using HttpClient. It also fails on the emulator. It seems erratic in when it fails.

  • Solve this using IP instead url. Try this.

  • EauditorEauditor USMember ✭✭

    I also got this strange exception when downgrading from Android 4.1 to 2.3 and moving the solution from Debug to Release. Strange.

  • CheesebaronCheesebaron DKInsider, University mod
    edited March 2014

    @ForceMagic‌ HttpClient is supported in PCL just grab the HttpClient from NuGet.

    EDIT: Oh nvm, someone vamped a thread again...

  • ForceMagicForceMagic USMember ✭✭

    @Cheesebaron‌ Is this new since the last release, because I remember almost a year ago, we had to use low level request because of PCL.

  • CheesebaronCheesebaron DKInsider, University mod

    It is new since PCL was officially released.

  • OFKOFK USMember ✭✭

    Get same problem on Galaxy s4 after upgrade to Android 4.3 and 4.4. And obviously only when connecting via WiFi

  • ForceMagicForceMagic USMember ✭✭

    @Cheesebaron‌ Ok, thanks. We will see if we can use that instead in the future, for now we'll stick with the low level Request since the system is done anyway.

  • EauditorEauditor USMember ✭✭

    We have this NameResolutionFailure problem on the emulator after first upgrading the Xamarin. Did you have a similar problem? In our case, the use of IP does not work, indicating that the emulator does not have access to the net.

  • ZecaCarZecaCar USMember

    Anyone got a solution?

  • KeyzerSKeyzerS NOMember ✭✭

    Hello! I get this problem if i havent restarted the emulator for a while. Ive never had it reoccur right after a restart of emulator and Xamarin. Seems like my emulator gets confused after a while.

  • BurridgeBurridge USMember

    I get this on my problem on my cell phone (Android Note 3) if I'm connected to the Wifi. Any wise words about this would be appreciated.

  • blade.2890blade.2890 USMember

    Someone has found a solution?

  • sarahzohar88sarahzohar88 USMember

    I also have this strange when you are downgrading from Android 4.1 to 2.3 and moving solution to debug to release.

  • SukrathMahajanSukrathMahajan USMember

    I had the same problem. I found that Data Plan on the Device was disabled some reason. In Galaxy S4->Settings->Data Usage-> Mobile Data , Check the check box.that should fix the issue.

  • You must use the IP address from which you invoke:

    rxcui var = "1";

    WebRequest request = HttpWebRequest.Create(string.Format(@"{0}", rxcui));

  • If you use a wifi with proxy

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited May 2014

    Deleted by author

  • shanminxushanminxu USMember

    We ran into the same issue, by reading one of the posts here found that wifi was the issue. This was fixed by using the LAN connection

  • OrenNovotnyOrenNovotny USMember, Insider, Beta, University ✭✭

    I'm hitting this with a brand new Galaxy S5 with the latest firmeware as of today (android 4.4.4). This is a dev phone and has no SIM card in it, only wifi...this is crazy.

    Any real solutions this? My app has the correct permissions and adding retries seems to work, but that shouldn't be needed.

  • CheesebaronCheesebaron DKInsider, University mod

    I still sometimes get this. However, if I keep creating requests using the same instance of HttpClient the exception eventually go away.

    So you could try something like Polly or create your own Retry Handler. It is not pretty, but I remember reading about people having troubles with some devices when writing Java as well, and what helps is to toggle the WiFi connection.

  • OrenNovotnyOrenNovotny USMember, Insider, Beta, University ✭✭

    @Cheesebaron‌ do you know if it happens with OkHttp (via ModernHttpClient) too or if that'd fix it?

  • CheesebaronCheesebaron DKInsider, University mod

    @OrenNovotny‌ yes, happens with that as well.

  • FB123FB123 CAMember ✭✭

    @OrenNovotny I'm running into the same issue... (with the same device setup) did you figure out the issue?

  • OrenNovotnyOrenNovotny USMember, Insider, Beta, University ✭✭

    No solution - just wound up using the Polly library to put a retry around it. It just seems flaky but retries work.

  • allen.8290allen.8290 USMember

    same problem in release version of android 4.4

Sign In or Register to comment.