System.Net.WebException Error: NameResolutionFailure



  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I've the same problem, but with SIM. with WIFI it works

  • Gilles.5055Gilles.5055 USMember

    Same problem when the device has a limited connectivity with the server, a timeout or airplane mode.
    I can catch the exception but the next instruction generates a "FATAL EXCEPTION: main".

    Any solution?

  • Gilles.5055Gilles.5055 USMember

    It seems that the root of the problem was because I prepended ".ConfigureAwait(false)" to "await" instructions.
    I removed it to the next awaitable instruction and now everything works as expected.

  • CheesebaronCheesebaron DKInsider, University mod

    I highly doubt the issue is .ConfigureAwait(false). The only thing it does is to not switch to the context we were on before calling await on the given Task when it returns. That has no implications on whether or not you will get a NameResolutionFailure.

  • Gilles.5055Gilles.5055 USMember
    edited July 2015

    Hi Tomasz,

    You are true, .ConfigureAwait(false) only throw an exception on the next awaitable instruction. There is no link with NameResolutionFailure which is caught in a try/catch.

    Example with failure:
    await Test1Async().ConfigureAwait(false);
    await Test2Async().ConfigureAwait(false); // => Crash

    Example with success:
    await Test1Async();
    await Test2Async(); // => Succeeded

    In the failure scenario there is no way to catch the exception wity a try/catch, the application directly crash. According to my tests that only happens when doing HTTP calls and when the user has a limited connectivity (e.g. airplane mode throwing NameResolutionFailure), something seems to break in Mono.

    I also saw on a forum that there was an issue in Xamarin Insights and the problem was because there was no try/catch in Mono for some HTTP calls. It does not seem to be fixed yet unless you manually upgrade Mono. This problem may be related.

  • CheesebaronCheesebaron DKInsider, University mod

    @Gilles.5055 That is true if your two methods Test1Async and Test2Async are void! If you return Task instead, the exception will bubble up.

    private async Task Test1Async()
  • MatengeleKaira.4735MatengeleKaira.4735 ZMMember, University

    Noticed none of the solutions suggested here worked for me so I have shared a post for what I did to resolve the problem on the link below.

  • Gilles.5055Gilles.5055 USMember

    @Cheesebaron Yes, all my methods return a Task or Task<T>, they are never a void.

  • EmyMa341EmyMa341 USMember ✭✭

    I have the same error but on iOS device, on wifi it works fine but on cellular 3G I get this exceptions

  • KimRasmussenKimRasmussen DKMember

    I use the HttpClient in a PCL and had the same problem on an Android device (worked fine on a Windows Phone).

    I got it working when I added the Host to the header: client.DefaultRequestHeaders.Host = "";

  • TylerFoucheTylerFouche USMember ✭✭

    Hey I am finding the same error on iOS and Android when using wifi + httpclient but only randomly. I can't use an ip to solve the problem because our servers have a load balancer and rotating IP's. Has anyone tried the RestSharp component and seen any different results?

  • Ambrose023Ambrose023 INMember

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

  • How we connect sql server into the Xamarin using visual studio

  • MasaabMasaab USMember

    I had the same issue. After rumbling with the error I found out my mobile wifi was not stable. I tried on my other samsung galaxy s6 plus and it worked fine. Also make sure you have ticked the INTERNET Permission. For reference the code below works for me.

    var client = new System.Net.Http.HttpClient(); System.Net.Http.HttpResponseMessage response1 = await client.GetAsync(@""); var placesJson = response1.Content.ReadAsStringAsync().Result; var content = JsonConvert.DeserializeObject<string>(placesJson);

  • SagarPanwalaSagarPanwala USMember ✭✭

    Anyone found the solution for this? Can any one from @XamarinCompany will respond to this?

  • HI,

    According to me...

    When you use a .NET client to consume a Web service through an HTTP proxy server, you may receive the following error message.
    you need to set your server setting and enable as proxy. Please refer to for your server setting.


  • soroush731soroush731 CAMember

    Same Problem
    please help

    string url = ""; // System.Net.WebException: Error: NameResolutionFailure
    // but url = "ipaddress/test.php"; works just fine
    // I wanna be able to use a domain name since the ip will just give me and not
    // Im using xamarin forms project from visual studio 2015 updated on june 9 2016
    string test= "test=342";
    await MakePostRequest(url, test, false);    
    public async Task<string> MakePostRequest(string url, string serializedDataString, bool isJson = true) {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                if (isJson)
                    request.ContentType = "application/json";
                    request.ContentType = "application/x-www-form-urlencoded";
                request.Method = "POST";
                var stream = await request.GetRequestStreamAsync();
                using (var writer = new StreamWriter(stream)) {
                var response = await request.GetResponseAsync();
                var respStream = response.GetResponseStream();
                using (StreamReader sr = new StreamReader(respStream)) {
                    return sr.ReadToEnd();
  • KobieWilliamsKobieWilliams USMember
    edited July 2016

    The error seems to be occurring when I create multiple instance of HttpClient. What worked for me was to use HttpClient in a singleton pattern. And then called it wherever I needed throughout my application.

    public sealed class HttpClientInstance
    private static readonly HttpClient HttpClient;
    static HttpClientInstance() { HttpClient = new HttpClient(); }
    public static HttpClient Instance
    return HttpClient;

    This is how I called it throughout my application.
    HttpClient client = HttpClientInstance.Instance;

  • JosephSauveJosephSauve USMember ✭✭
    edited July 2016

    I know how stupidly simple this sounds, but try setting the emulator's network to cellular data instead of WiFi.

    I recently started seeing the NameResoutionFailure errors in the Visual Studio Emulator for Android while working at a hotel. And then at a conference later the same day, the app ran fine; no NameResolutionFailure messages.

    And then the next day, I was on the Microsoft campus and was seeing the NameResolutionFailure errors return. After much searching for solutions and gnashing of teeth, I found this SO answer:

    To my surprise, as soon as I enabled cell data in the emulator instead of assuming that WiFi would just work, the NameResolutionErrors disappeared and my app was able send and receive data just fine.

    Since I'm using the Visual Studio Emulator for Android, I didn't enable cell data in the operating system itself (as in the SO answer), but in the emulator settings panel. The Visual Studio Emulator for Android has a radio button in its settings that allows you to select WiFi or Cellular, under the "Network" tab.

    As has been mentioned before, the root of the problem is probably some kind of proxy in the network that your host computer is attached to. As to why switching to Cellular instead of WiFi in the emulator resolves it...I have no idea. But it seems to have solved it for me.

  • EmmarexEmmarex USMember ✭✭

    I had the same issue just adding

    fix the issue for me.

  • EmmarexEmmarex USMember ✭✭

    I had the same issue but adding the 'uses-permission android:name="android.permission.INTERNET" ' solved the WebException issue.

  • HatefGhaniHatefGhani USMember

    I resoved it!
    on your device, your wifi is off!

  • N.Y.GudlanurN.Y.Gudlanur USMember


    I found solution for that the device should be online when working with webapi/Wcf service.


  • If you set any special character in the cookie (like, you may get this error.
    You need to do URL encode and before setting any value to the cookie

  • ChrisColeTechChrisColeTech USMember ✭✭✭
    edited September 2016

    Unhandled managed exception:
    Error: NameResolutionFailure (System.Net.WebException)

    How do you handle this exception and enable offline mode?

    I'm using Azure App Mobile Service client and server for Xamarin.iOS...

    I get this when the app is in airplane mode

  • There seems to be a bug in Xamarin Cycle 7.
    Stumbled across the same issue and fixed it by calling the full domain url of the web api service instead of the IP.

  • imkumarsaurabhimkumarsaurabh INMember ✭✭

    I also faced lot of issues ( NameResolutionfailure) using httpClient, but later when I used WebClient I haven't faced issue till then.

  • MatheusGVerasMatheusGVeras USMember
    edited October 2016

    Simple add uses-permission android:name="android.permission.INTERNET" to the manifest android project

  • gabooboogabooboo USMember ✭✭

    @Eauditor said:
    And we solved it by setting permission app:Internet

    Thank you @Eauditor I finally solved by setting permission INTERNET. Thanks.

  • HelenMamalakiHelenMamalaki GBUniversity ✭✭

    In Android manifest enabling the 'Internet' permission fixed this for me. Thanks to @Eauditor for the solution.

  • Just for reference, @Eautitor solution solved it for me on a Galaxy S4 running Android 5.1. Many thanks!

  • MeysamKhoshbakhtMeysamKhoshbakht USMember ✭✭

    My problem solved by this code:

    var client = new HttpClient {
    BaseAddress = new Uri(""),
    DefaultRequestHeaders = { Host = "" }

  • minaFawzy.1775minaFawzy.1775 USMember ✭✭

    have the same issue , I believe this issue because of your internet connect , it may be show it connect but in fact its not

  • And I also have this issue

  • 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 :-)

  • pallavboharapallavbohara USMember ✭✭

    In my case IP was not mapped to particular Url. Beforehand i was using http://abcd48:8080/dashboard Now i am using for testing

  • Any Solution

  • rozgonyirozgonyi USMember

    @DesOwen.5671 said:
    For me, in release mode, I checked the box marked Internet in the Required permissions section of the AndroidManifest.xml file found under the Properties folder. Debug mode doesn't need this checked but Release mode does - which you need if sending the APK by email for installation - which works great by the way. In case anyone is interested, you also have to sign your app and produce the private key following these instructions here:,testing,_and_metrics/publishing_an_application/part_2-_publishing_an_application_on_google_play/

    You saved my life. :) thanks.

  • ManojkumarMaliManojkumarMali USMember ✭✭✭

    Solved by changing network....

Sign In or Register to comment.