title: Image.FromStream() method returns Invalid Argument exception
body: <p>I am capturing images from a smart camera imager and receiving the byte array from the camera through socket programming (.NET application is the client, camera is the server). </p>
  
  <p>The problem is that i get System.InvalidArgument exception at runtime.</p>
  
  <pre><code>private Image byteArrayToImage(byte[] byteArray) 
  {
      if(byteArray != null) 
      {
          MemoryStream ms = new MemoryStream(byteArray);
          return Image.FromStream(ms, false, false); 
          /*last argument is supposed to turn Image data validation off*/
      }
      return null;
  }
  </code></pre>
  
  <p>I have searched this problem in many forums and tried the suggestions given by many experts but nothing helped.</p>
  
  <p>I dont think there is any problem with the byte array as such because When i feed the same byte array into my VC++ MFC client application, i get the image. But this doesn't somehow work in C#.NET.</p>
  
  <p>Can anyone help me ?</p>
  
  <p>P.S :</p>
  
  <p>Other methods i've tried to accomplish the same task are:</p>
  
  <p>1.</p>
  
  <pre><code>private Image byteArrayToImage(byte[] byteArray)
  {
      if(byteArray != null) 
      {
          MemoryStream ms = new MemoryStream();
          ms.Write(byteArray, 0, byteArray.Length);
          ms.Position = 0; 
          return Image.FromStream(ms, false, false);
      }
      return null;
  }
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>private Image byteArrayToImage(byte[] byteArray) 
  {
      if(byteArray != null) 
      {
          TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap));
          Bitmap b = (Bitmap)tc.ConvertFrom(byteArray);
          return b;
      }
      return null;
  }
  </code></pre>
  
  <p>None of the above methods worked. Kindly help.</p>