Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何修复Xamarin';System.ArgumentNullException:';值不能为null。参数名称:地址';例外情况_C#_Xamarin_Udp - Fatal编程技术网

C# 如何修复Xamarin';System.ArgumentNullException:';值不能为null。参数名称:地址';例外情况

C# 如何修复Xamarin';System.ArgumentNullException:';值不能为null。参数名称:地址';例外情况,c#,xamarin,udp,C#,Xamarin,Udp,构建和运行应用程序时,我得到一个“System.ArgumentNullException:”值不能为null。参数名称:地址“异常” 异常指向这段代码,指向初始化端点的行: public void sendInstruction(string instruction) { char[] charInput = instruction.ToCharArray(); Byte[] sendBytes = Encoding.ASCII.GetBytes(cha

构建和运行应用程序时,我得到一个“System.ArgumentNullException:”值不能为null。参数名称:地址“异常”

异常指向这段代码,指向初始化端点的行:

public void sendInstruction(string instruction)
    {
        char[] charInput = instruction.ToCharArray();
        Byte[] sendBytes = Encoding.ASCII.GetBytes(charInput);
        IPEndPoint epWK = new IPEndPoint(ip, port);
        udp.Send(sendBytes, sendBytes.Length, epWK);
    }
所有参数都在以下步骤之前定义:

public IPAddress ip;
public int port;
UdpClient udp = new UdpClient();
并设置:

ip = IPAddress.Parse("192.168.178.62");
port = 54490;

代码以前工作过,所以我不理解为什么会触发此异常。

可能在调用sendInstruction之前不会调用初始化ip的代码。

它告诉您
ip
为空,调试并检查
ip
的值,不要因为错误告诉您不是这样,就假定它不是空的。请发一封邮件,我们可以帮你。