This project has moved. For the latest updates, please go here.

Problem when compiling with .NET 4.0

Coordinator
Sep 4, 2010 at 11:31 AM

(copied from email):

Hello,

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, 
       Nito.Async.Sync.SynchronizeAsyncCallback(
           (asyncResult) =>
                { Sync.InvokeAndCallback(() => Socket.EndSend(asyncResult), OnWriteCompleted,
                    asyncResult.AsyncState); }),
        state);
}

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 ?
Sebastien

Coordinator
Sep 4, 2010 at 11:35 AM

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.

       -Steve