System.FormatException: 指定了无效的 IP 地址

本文介绍了一种在断点调试过程中遇到的IP地址显示异常问题及其解决方案。当IP地址中出现多个不可见的''字符时,通过循环复制IP地址到一个字符串并添加判断条件来解决该问题。

经断点调试发现ip为10.8.0.10\0\0\0\0\0\0\0\0;打印出来为10.8.0.10,里面多了很多的\0,但是又不打印出来,所以对于新手来说这个问题估计解决不了。下面博主给出解决办法:
1.循环复制IP地址到一个字符串,再添加一条判断
if (recv_text.ElementAt(i) == ‘\0’)
break;
2.其他的大同小异,自己灵活变通,道理一样的。

System.ArgumentNullException HResult=0x80004003 Message=值不能为 null。 Parameter name: ipString Source=System StackTrace: at System.Net.IPAddress.InternalParse(String ipString, Boolean tryParse) at System.Net.IPAddress.Parse(String ipString) at WindowsFormsAppp10_2.Class1.Send(String strServer, String strContent) in D:\Users\24654\source\repos\WindowsFormsAppp10-2\Class1.cs:line 50 at WindowsFormsAppp10_2.Form1.button1_Click(Object sender, EventArgs e) in D:\Users\24654\source\repos\WindowsFormsAppp10-2\Form1.cs:line 33 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at WindowsFormsAppp10_2.Program.Main() in D:\Users\24654\source\repos\WindowsFormsAppp10-2\Program.cs:line 19
06-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值