title: C#: AsyncCallback not being called on Socket.BeginReceive
body: <p>I have a serious problem with the asynchronous Receive method of System.Net.Sockets.Socket.</p>
  
  <p>Here is the code I use to open the connection:</p>
  
  <pre><code>_socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
  _socket.Connect(endpoint);
  
  byte[] buffer = new byte[1024];
  _socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, ReceiveCallback, buffer);
  </code></pre>
  
  <p>and here is the callback method:</p>
  
  <pre><code>private void ReceiveCallback(IAsyncResult result)
  {
       byte[] buffer = (byte[])result.AsyncState;
       int count = _socket.EndReceive(result);
  
       if (count &gt; 0)
       {
            // Do something
       }
  
       buffer = new byte[1024];
       _socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, ReceiveCallback, buffer);
  }
  </code></pre>
  
  <p>The problem is that the ReceiveCallback is never being called, despite the socket being connected.</p>
  
  <p>Can anyone help me out on this one?</p>