While coding the multi-platform way – with Microsoft .NET framework on Windows and Mono on everything else we discovered an annoying bug. In some source-code examples that deal with networking you often see something like this:
Socket listener = new Socket(0, SocketType.Stream, ProtocolType.Tcp);
This short code-snippet instantiates a new socket object. Mono compiles this code without any error or warning. But when you run it… this shows up:
Unhandled Exception: System.Net.Sockets.SocketException: Protocol not supported in <0x00100> System.Net.Sockets.Socket:.ctor (AddressFamily family, SocketType type, ProtocolType proto) in <0x00068> HTTPServer.HttpServer:listen () in (wrapper delegate-invoke) System.MulticastDelegate:invoke_void ()
Note: this doesn’t happen with .NET 1.1 and .NET 2.0 on Windows.
You can solve this exception just by telling mono which AdressFamily should be used:
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Thanks to Ello for his help.