title: A generic error occurred in GDI+ at System.Drawing.Image.Save
body: <p><em><strong>Exception:</em></strong></p>
  
  <blockquote>
    <p><strong>A generic error occurred in GDI+.
     at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
     at System.Drawing.Image.Save(String filename, ImageFormat format)
     at System.Drawing.Image.Save(String filename)</strong></p>
  </blockquote>
  
  <p><em><strong>Code:</em></strong></p>
  
  <pre><code>byte[] bitmapData = new byte[imageText.Length];
  MemoryStream streamBitmap;
  bitmapData = Convert.FromBase64String(imageText);
  streamBitmap = new MemoryStream(bitmapData);
  System.Drawing.Image img = Image.FromStream(streamBitmap);
  img.Save(path);
  </code></pre>
  
  <p>We convert a base64 string into a MemoryStream and then create a System.Drawing.Image (Image.FromStream(streamBitmap)).
  At the end the image is saved in a temp file.</p>
  
  <p>The strange thing is that the problem seems to occur when the activity (number of concurrent users) is high on the web server and the problem is solved temporarily after an IISRESET or an application pool recycle...</p>
  
  <p>==> Garbage collector issue ?</p>
  
  <p>I already checked the permission of the TEMP folder... </p>