C# TcpClient.NoDelay Exception

Hi, quick question on a weird behavior when checking a boolean:

I have a TcpClient socket where I turn off Nagle’s algorithm by setting “TcpClient.NoDelay = true”

It seems to work and everything, which is great, but the weird part is if I go to check the returned value of TcpClient.NoDelay I am getting a “InvalidCastException: Cannot cast from source type to destination type.”

This does not work:

myTcpClient.NoDelay = true;
Debug.Log ("Check TcpClient.NoDelay: " + myTcpClient.NoDelay); // Causes: InvalidCastException: Cannot cast from source type to destination type.

This does work by checking NoDelay directly from myTcpClient’s underlying socket:

myTcpClient.NoDelay = true;
Debug.Log ("Check Socket.NoDelay: " + myTcpClient.Client.NoDelay);

For your convenience, here’s the MSDN pages for the TcpClient and Socket class’s NoDelay function:

Should I be asking this question on stackoverflow instead? I thought to ask here first because it seems like some weird C# Mono implementation issue.

Thanks!

Use a raw socket instead of TcpClient.

Care to explain why? Is there some bug with Mono’s implementation of TcpClient that bites people? I haven’t had any problems with the class so far, other than this, and this isn’t a show stopping problem, per se… just an odd behavior that I was curious about.