This project has moved and is read-only. For the latest updates, please go here.

Problem when compiling with .NET 4.0

Sep 4, 2010 at 12:31 PM

(copied from email):


I have got a compile error i connot solve when compiling nito 1.4 with .NET 4.0 :
in tcpsocket.cs :

public void WriteAsync(byte[] buffer, int offset, int size, object state)
    Socket.BeginSend(buffer, offset, size, SocketFlags.None, 
           (asyncResult) =>
                { Sync.InvokeAndCallback(() => Socket.EndSend(asyncResult), OnWriteCompleted,
                    asyncResult.AsyncState); }),

The compiler claims the call to Sync.InvokeAndCallback beeing ambiguous between InvokeAndCallback and InvokeAndCallback<int>.

I am not familiar with lambda expression and cannot solve this. Could you give me help, please ?

Sep 4, 2010 at 12:35 PM

This is one of the C# 2010 breaking changes (method group type inference).

The simplest fix is to wrap the "() => Socket.EndSend(asyncResult)" in parenthesis and cast it to "Action", as such:

Socket.BeginSend(buffer, offset, size, SocketFlags.None, Sync.SynchronizeAsyncCallback((asyncResult) =>
    Sync.InvokeAndCallback((Action)(() => Socket.EndSend(asyncResult)),
        OnWriteCompleted, asyncResult.AsyncState);
}), state);

This will force the 4.0 C# compiler to use the same overload that the 3.5 C# compiler would choose.