“Invalid argument” when setting options on a multicast socket
Okay, check check check it:
private static void Main(string[] args)
{
try
{
Socket mcSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);mcSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse(“224.168.100.2”)));
// purposefully throw a null exception here to show that WriteException is working
Socket tempSocket = null;
if (tempSocket.SocketType == SocketType.Dgram)
{
// crash here
}
}
catch (Exception e)
{
WriteException(e);
}
}private static void WriteException(Exception e)
{
Console.Out.WriteLine(“”);
Console.Out.WriteLine(”—————- Exception——————”);
Console.Out.WriteLine(“e.Message = {0}”, e.Message);if (e.InnerException != null)
{
WriteException(e.InnerException);
}
}
Would you expect that innocent looking call to SetSocketOption to cause mayhem and mischief? Well, in one case, it does. And I have no idea why.
I get an “Invalid argument supplied” error (WinSock error 10022) on a certain person’s machine when making that call. What gives? What’s going on underneath that could cause this?
Things that are not causing it:
- A firewall is not running
- There is a network card in the computer
- The correct version of .NET is installed
- Windows XP Service Pack 2 is installed
- Not getting flagged by anti-virus software
I’m stumped.
March 2nd, 2005 at 2:13 pm
I am also experiencing the same problem. Have you found the reason for the exception?
System.Net.Sockets.SocketException: An invalid argument was supplied
March 2nd, 2005 at 9:58 pm
Never did figure it out… I ended up trapping the exception and logging it. It seems to be an edge-case, but all the searching I did turned up nothing.
Windows does this funny thing where it sometimes uninstalls the network stack when it doesn’t detect a ‘net connection… wasn’t what was going on here, but maybe that can help you? If you’re multicasting on a local machine (TTL 0) and it’s not working that might be the cause?
The only thing I have left is that it’s a hardware problem or OS setup problem.