无法在Xamarin Mac

时间:2017-01-28 08:35:46

标签: c# macos xamarin.mac

我正在尝试在Xamarin.Mac中获取当前计算机的IP地址。我正在使用这个C#代码,它在Windows中运行得非常好,但是对于Xamarin.But在Mac上它会抛出一个

  

System.Net.Sockets.SocketException

以下是代码I' m使用:

public override void AwakeFromNib()
    {
        base.AwakeFromNib();
        try
        {

            IPHostEntry IPHost = Dns.GetHostEntry(Dns.GetHostName());
            combo_box.UsesDataSource = true;
            combo_box.Add(new NSString("127.0.0.1"));
            foreach (IPAddress item in IPHost.AddressList)
            {
                combo_box.Add(new NSString(item.ToString()));
            }

            Clients clt = GetLatestClient();
            if (!String.IsNullOrEmpty(clt.ServerIP) && !String.IsNullOrEmpty(clt.ipadd))
            {
                ServerIpAddress = clt.ServerIP;
                IpAddressVal = clt.ipadd;
                //ClientForm serverMaster = new ClientForm();
                //serverMaster.Show();
                //BeginInvoke(new MethodInvoker(Hide));
            }
        }

以下是抛出的异常:

  

无法解析主持人名称'

Exception thrown

1 个答案:

答案 0 :(得分:0)

如果你有一个简单的控制台应用程序,这是否有效?

它可能不是特定的Xamarin.Mac,而只是与mono的实现差异。

相关问题