When converting PDF pages to PNG an error occurred

We are converting pdf pages to png image one by one , this code sometime gives error on iis server
error is : A generic error occurred in GDI+.

main points:
this issue never happens on my local server
always happens on iis ust or production server randomly
goes after some idle time by its own
image is created on the location but with 0 kb size
aspose.pdf dll version is 20.8
.net framework is 4.5.1

error occurs at this line : pngDevice.Process(doc.Pages[pageCount], imageStream);
Below is my Code:
if(uploadfile== null)
{
uploadfile = Path.Combine(ConvertFolderPath, “output” + g + “.pdf”);
}
//Document doc = new Document(Path.Combine(ConvertFolderPath, “output” + g + “.pdf”));
Document doc = new Document(uploadfile);
string Aratio = “”;
string pages = “”;
string Ratios = “”;
string height = “”;
string Allheights = “”;
string fields = “”;
int TotalPages = 0;
//bool licensed = CheckLicense();
//if (licensed || (!licensed && doc.Pages.Count <= 4))
// TotalPages = doc.Pages.Count;
//else
// TotalPages = 4;
TotalPages = doc.Pages.Count;
var abc = doc.PageInfo;

            //Create Resolution object
            // Resolution resolution = new Resolution(150);
            //create PNG device with specified attributes
            Aspose.Pdf.Devices.PngDevice pngDevice = new Aspose.Pdf.Devices.PngDevice();

            for (int pageCount = 1; pageCount <= TotalPages; pageCount++)
            {
                Guid guid = Guid.NewGuid();
                string image1Name = "image-1-" + guid + ".png";
                //Console.Write("clear0");
                // using (FileStream imageStream = new FileStream($"{InputFolderPath}{image1Name}", FileMode.Create))
                using (FileStream imageStream = new FileStream(Path.Combine(InputFolderPath, image1Name), FileMode.Create))                 
                {
                    //Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices.JpegDevice();
                    //Convert a particular page and save the image to stream
                    pngDevice.Process(doc.Pages[pageCount], imageStream);
                    //Close stream
                    imageStream.Close();
                }


                //Console.Write("clear1");
                System.Drawing.Image image = System.Drawing.Image.FromFile(Path.Combine(InputFolderPath, image1Name));
                guid = Guid.NewGuid();
                string image2Name = "image_" + guid + "_p_" + pageCount + ".png";
                using (var newImage = ScaleImage(image, 1138, 760, Path.Combine(InputFolderPath, image2Name), out height, out Aratio))
                {
                    newImage.Save(Path.Combine(InputFolderPath, image2Name));
                }
                image.Dispose();

please help us to resolve this issue .

@harsh.gupta519

Would you kindly try using 23.8 version of the API? In case issue still persists, please share your sample PDF document with us. We will test the scenario in our environment and address it accordingly.