title: C# ReceiveAsync Error
body: <p>Im currently developing an appserver. I would like to use AcceptAsync method. I got error "Object reference not set to instance of object." when calling ReceiveAsync method. If there any come up with this problem and got the solution to it?</p>
  
  <pre><code>public class AppServer
  {
      public void Start()
      {
          Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
          serverSocket.Bind(new IPEndPoint(IPAddress.Any, 12345));
          serverSocket.Listen(100);
  
          SocketAsyncEventArgs e = new SocketAsyncEventArgs();
          e.Completed += new EventHandler&lt;SocketAsyncEventArgs&gt;(e_Completed);
  
          bool raiseEvent = serverSocket.AcceptAsync(e);
          if (!raiseEvent)
              AcceptCallback(e);
      }
  
      void e_Completed(object sender, SocketAsyncEventArgs e)
      {
          AcceptCallback(e);
      }
  
      private void AcceptCallback(SocketAsyncEventArgs e)
      {
          SocketAsyncEventArgs readEventArgs = new SocketAsyncEventArgs();
          readEventArgs.Completed += new EventHandler&lt;SocketAsyncEventArgs&gt;(readEventArgs_Completed);
  
          Socket clientSocket = e.AcceptSocket;
          bool raiseEvent = clientSocket.ReceiveAsync(readEventArgs); // &lt;-- Error goes here
          if (!raiseEvent)
              ReceiveCallback(readEventArgs);
      }
  
      void readEventArgs_Completed(object sender, SocketAsyncEventArgs e)
      {
          ReceiveCallback(e);
      }
  
      private void ReceiveCallback(SocketAsyncEventArgs e)
      {
  
      }
  }
  </code></pre>