I have an ASP.NET-MVC project where I need to dynamically generate some png images. That's easy. I just create ActionResult that returns FileSreamResult object. To generate images I used classes from System.Drawing such as Bitmap and Image. Everything works fine on local machine and on production server. But when IIS on production server shuts down my application pool due to inactivity and starts it again, image generation starts to fail.
Problem was in code that tries to save image to the stream:
var imageStream = new MemoryStream();
bmp.Save(imageStream, ImageFormat.Png);
Exception is: System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+. So there is no much help. I tried a different solutions and nothing helps. After I have found this topic Alternatives to System.Drawing for use with ASP.NET?
The main idea of this topic is:
Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.
So I decided to use WPF classes to generate images. I rewrote all image generation code, but now I get another error after app pool restart. Exception: System.Runtime.InteropServices.COMException (0x88982F8A): Exception from HRESULT: 0x88982F8A. This happens when I try to save my PngBitmapEncoder to stream
var stream = new MemoryStream();
encoder.Save(stream);
Maybe anyone encountered this problem or just have any ideas?
Here's an unsatisfactory answer...
I was getting the same error when I first deployed my new image generation functionality.
I stopped the corresponding application pool, restarted it again, and it worked.
I cant answer your question as such but if this only occurs because your app shuts down, why not set its Idle to 0 (app pool -> App -> Advanced Options ), then it wont shut down.
It may be a last resort if you cant get a suitable answer.
User contributions licensed under CC BY-SA 3.0