"UNHANDLED EXCEPTION: System.Net.Sockets.SocketException: No such host is known" only on Release

AsgeirAsgeir ISMember
edited March 2013 in Xamarin.Android

Description of Problem:
Using Xamarin Studio 4.0.3 (build 13) on Windows 7 with Build set to Release:

 "UNHANDLED EXCEPTION: System.Net.Sockets.SocketException: No such host is known"

This only occurs when build is set to Release, Debug runs without error?

Take the following code as example:

public class Activity1 : Activity

    protected override void OnCreate (Bundle bundle)
        base.OnCreate (bundle);

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button> (Resource.Id.myButton);

        button.Click += delegate {
            button.Text = IPAddress();

    public string IPAddress()
        string hostName = System.Net.Dns.GetHostName();
        System.Net.IPHostEntry hostInfo =
        return hostInfo.AddressList[0].ToString();

Set Build action to Release and Run

Actual Results:
UNHANDLED EXCEPTION: System.Net.Sockets.SocketException No such host is known

Expected Results:
Runs without error in Debug. Consistent results between Debug and Release

How often does this happen?
All the time


  • LluisSanchezLluisSanchez ESXamarin Team Xamurai

    Moved to Android forum.

  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    Your app is missing the INTERNET permission. This is added by default to Debug projects but not Release projects, and is required in order to access network resources.

Sign In or Register to comment.