I have an ASP.NET-MVC project where I need to dynamically generate some png images. It's simple. I just create an ActionResult that returns a FileSreamResult object. To generate images, I used classes from System.Drawing, such as Bitmap and Image. Everything works fine on the local machine and on the production server. But when IIS on the production server shuts down my application pool due to inactivity and starts it again, image generation fails.
The problem was in the code that tries to save the image in the stream:
var imageStream = new MemoryStream();
bmp.Save(imageStream, ImageFormat.Png);
Exception: System.Runtime.InteropServices.ExternalException (0x80004005): A general error occurred in GDI +. Therefore there is no help. I have tried different solutions and nothing helps. After I found this topic, System.Drawing alternatives for use with ASP.NET?
The main idea of ββthis topic:
Classes in the System.Drawing namespace are not supported for use in a Windows service or ASP.NET. Attempting to use these classes from one of these application types can cause unforeseen problems, such as degraded service performance and runtime exceptions.
WPF . , . :
System.Runtime.InteropServices.COMException(0x88982F8A): HRESULT: 0x88982F8A. , PngBitmapEncoder
var stream = new MemoryStream();
encoder.Save(stream);
, - - ?