Reputation: 241
I've written a PDF generation API that uses dinktopdf to convert some templated HTML to a byte array. This all works fine on my local machine but when I deploy to my azure web application the API only works once. When I try it a second time I get the following message and a 502 error:
The specified CGI application encountered an error and the server terminated the process.
Here's a stripped down version of my code that still presents the same error:
static IPdfConverter pdfConverter = new SynchronizedConverter(new PdfTools());
public static byte[] BuildPdf(string html)
{
return pdfConverter.Convert(new HtmlToPdfDocument()
{
Objects =
{
new ObjectSettings
{
HtmlContent = html
}
}
});
}
I've also tried using IronPDF to do the HTML to PDF conversion and gotten the same exact issue (works perfectly on local machine but only once on Azure deployment before giving consistent 502 errors).
Upvotes: 5
Views: 4125
Reputation: 151
If you initialize converter with var converter = new SynchronizedConverter(new PdfTools());´, remove it, and just inject
IConverterin your service.
I tried and this approach is working, after all, we already register the converter, we don't need to create an instance using the
new` keyword. My app is not on Azure, but I have the same problem, the converter hangs after the first call, for that reason I decide to write down this comment.
Upvotes: 7
Reputation: 241
Update: Problem was solved by changing the Azure App Service Plan to Basic rather than free (PDF generation requires at minimum the Basic plan apparently).
Upvotes: 6