Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UdpClient Constructor Throwing SocketException

Tags:

c#

sockets

I'm experiencing an exception upon construction of a UdpClient object, specifying the IPv4 family. This is only occuring on one Windows 7 64-bit machine, other machines with the same OS are working fine.

The precise exception is:

System.Net.Sockets.SocketException (0x80004005): An invalid argument was supplied
   at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
   at System.Net.Sockets.UdpClient.createClientSocket()

SocketException.ErrorCode is WSAEINVAL 10022, InvalidArgument.

The code that's throwing this exception:

this.udpClient = new UdpClient(AddressFamily.InterNetwork);

Can anyone explain what this exception is telling me? How can IPv4 be an invalid argument for a new UDP client?

UPDATE: This is only occurring when running the application from a network drive. Running it locally does not cause this exception.

like image 289
Mark Avatar asked Mar 26 '26 17:03

Mark


1 Answers

The docs advise you to check SocketException::ErrorCode in this instance. What's the value of that? Should be instructive. The Family param is fine, I would think, or you would get ArgumentException.

If you receive a SocketException, use SocketException::ErrorCode to obtain the specific error code. Once you have obtained this code, you can refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error.

like image 110
Steve Townsend Avatar answered Mar 29 '26 05:03

Steve Townsend