在运行Windows 7 x64和VS2012 U1和使用.NET 4的两个系统我得到的错误“一个无效的参数提供的”如果我叫UdpClient或TcpClient的。
我已经尝试了许多端口,我已经验证该端口尚未约束,但每次都遇到了同样的错误。
我也试着运行使用提升的权限代码无济于事。
测试代码:
try
{
using (UdpClient client = new UdpClient(new IPEndPoint(IPAddress.Any, 123)))
{
Console.WriteLine("Port is open");
}
}
catch (SocketException error)
{
Console.WriteLine("Error:\n{0}", error.Message);
}
错误输出:
System.Net.Sockets.SocketException was unhandled
HResult=-2147467259
Message=An invalid argument was supplied
Source=System
ErrorCode=10022
NativeErrorCode=10022
StackTrace:
at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
at System.Net.Sockets.UdpClient..ctor(IPEndPoint localEP)
at GetNTPTime.Program.Main(String[] args) in z:\My Documents\Dropbox\Dev\C#\_Example\GetNTPTime\GetNTPTime\Program.cs:line 15
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
作为一个说明,我得到,如果我只需调用UdpClient客户端=新的UdpClient()同样的错误;