Mark
Mark

Reputation: 345

UdpClient Constructor Throwing SocketException

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.

Upvotes: 3

Views: 2870

Answers (2)

Steve Townsend
Steve Townsend

Reputation: 54178

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.

Upvotes: 1

Peter
Peter

Reputation: 27944

0x80004005 is an access denied, you do not have rights to create a socket, maybe your firewall?

Or your socket is in use, have you killed the program without terminating the socket?

Upvotes: 0

Related Questions