Troubleshooting .NET 6.0 Azure Function App with IronPdf on Azure

412 Views Asked by At

I'm encountering an issue with a .NET 6.0 (LTS) Azure Function App on Windows, using the elastic premium plan. My application runs locally but not on Azure. I'm following guidelines from IronSoftware on How to Run HTML to PDF with .NET on Azure? and insights from a related Stack Overflow post. Initially, I considered .NET 6.0 (Isolated), but reverted due to reported support issues.

Here's where I'm at:

Local Development: The app runs locally on .NET 6.0 but had to copy the runtime to the bin directory. I'm unsure if this step is necessary for a publish build or in the Azure environment, since its for Azureite local storage.

Testing: The app works as expected locally.

Deployment: I've used a publish profile, disabled 'run as package', and added extensive logging. However, the app fails on Azure when running the code from the Ironsoft example.

failing here:

log.LogInformation("About to render pdf...");
ChromePdfRenderer renderer = new ChromePdfRenderer();
using var doc = renderer.RenderUrlAsPdf("https://www.google.com/");
log.LogInformation("finished rendering pdf...");

example code:

log.LogInformation("Entered PrintPdf API function...");
        IronPdf.Installation.LicenseKey = "MYCOMPANYKEY"; 
        IronPdf.Logging.Logger.EnableDebugging = false;
        IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom;
        IronPdf.Logging.Logger.CustomLogger = log;
        Installation.LinuxAndDockerDependenciesAutoConfig = false;
        Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled;
        try
        {
            log.LogInformation("About to render pdf...");
            ChromePdfRenderer renderer = new ChromePdfRenderer();
            using var doc = renderer.RenderUrlAsPdf("https://www.google.com/");
            log.LogInformation("finished rendering pdf...");
            //return new FileContentResult(doc.BinaryData, "application/pdf") { FileDownloadName = "google.pdf" };
        }
        catch (Exception e)
        {
            log.LogError(e, "Error while rendering pdf", e);
        }

Error Details:

Type Details
Trace Severity level: Information, Message: Entered PrintPdf API function...
Trace Severity level: Information, Message: About to render pdf...
Trace Severity level: Information, Message: ---------- Microsoft Windows NT 10.0.20348.0 (C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit\IronSoftware.log) ----------
Trace Severity level: Information, Message: Initializing local Chrome client...
Trace Severity level: Information, Message: Using deployment directory 'C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit'
Trace Severity level: Information, Message: Creating deployment candidates using root path 'C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit' (download: True)
Trace Severity level: Information, Message: Creating folder deployments for win-x64
Trace Severity level: Information, Message: Creating embedded deployments for win-x64
Trace Severity level: Information, Message: Creating nuget deployments for IronPdf.Native.Chrome.Windows
Trace Severity level: Information, Message: Creating nuget deployments for IronPdf.Native.Chrome.Windows.Windows
Trace Severity level: Information, Message: Attempting deployment for 'Chrome' 2023.11.0.20149 using 'C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit'
Trace Severity level: Information, Message: Failed to locate assembly(s) for deployment 'C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit' at path 'C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit'
Trace Severity level: Information, Message: IronSoftware.Exceptions.IronSoftwareAssemblyMissingException: Failed to locate 'IronInterop' at 'C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit'
Trace Severity level: Information, Message: Successfully located 'IronInterop' at 'C:\home\site\wwwroot\bin\runtimes\win-x64\native'
Trace Severity level: Information, Message: Determining deployment commands for platform 'Windows' v10.0.20348.0
Trace Severity level: Information, Message: Using deployment instructions for 'default' v
Trace Severity level: Information, Message: Attempting to load Windows library 'C:\home\site\wwwroot\bin\runtimes\win-x64\native\IronInterop.dll'
Trace Severity level: Information, Message: Attempting to load Windows library 'C:\home\site\wwwroot\bin\runtimes\win-x64\native\IronInterop.dll'
Trace Severity level: Information, Message: Successfully loaded native library from 'C:\home\site\wwwroot\bin\runtimes\win-x64\native\IronInterop.dll'
Trace Severity level: Information, Message: Successfully loaded 'IronInterop' version '2023.11.0.20149' from 'C:\home\site\wwwroot\bin\runtimes\win-x64\native'
Trace Severity level: Information, Message: Successfully deployed 'Chrome' using 'C:\home\site\wwwroot\bin\runtimes\win-x64\native'
Trace Severity level: Information, Message: Initializing Chrome renderer for OS Name: Windows, Identifier: win, Version: 10.0.20348.0, VersionName: , Domain: Microsoft.Azure.WebJobs.Script.WebHost, Thread: .NET ThreadPool Worker, Path: C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit
Trace Severity level: Information, Message: Creating new job collection resource
Trace Severity level: Information, Message: 21:11:53 (4888): ~ Chrome renderer v2023.11.0.20149~
Trace Severity level: Information, Message: 21:11:53 (4888): register JobManager as publisher for event_readyToInitializeNetworkEventsDevToolsHandler
Trace Severity level: Information, Message: 21:11:53 (4888): [EventRegistry] Register event_readyToInitializeNetworkEventsDevToolsHandler for a publisher
Trace Severity level: Information, Message: 21:11:53 (4888): IsSingleProcess: 0
Trace Severity level: Information, Message: 21:11:53 (4888): Creating Cef proxy controller
Trace Severity level: Information, Message: 21:11:53 (4888): Creating Cef interface
Trace Severity level: Information, Message: 21:11:53 (4888): Created new lifespan events
Trace Severity level: Information, Message: 21:11:53 (4888): Created new load handler
Trace Severity level: Information, Message: 21:11:53 (4888): Created new render handler
Trace Severity level: Information, Message: 21:11:53 (4888): Created new print handler
Trace Severity level: Information, Message: 21:11:53 (4888): Created new dev tools handler
Trace Severity level: Information, Message: 21:11:53 (4888): JobManager subscribes a new sub, eventStr=event_readyToInitializeNetworkEventsDevToolsHandler
Trace Severity level: Information, Message: 21:11:53 (4888): Created new dev tools registration factory
Trace Severity level: Information, Message: 21:11:53 (4888): Created new lifespan handler
Trace Severity level: Information, Message: 21:11:53 (4888): Assigning Cef proxy controller events...
Trace Severity level: Information, Message: 21:11:53 (4888): Created new lifespan events
Trace Severity level: Information, Message: 21:11:53 (4888): Created new load handler
Trace Severity level: Information, Message: 21:11:53 (4888): Created new render handler
Trace Severity level: Information, Message: 21:11:53 (4888): Created new print handler
Trace Severity level: Information, Message: 21:11:53 (4888): Created new dev tools handler
Trace Severity level: Information, Message: 21:11:53 (4888): JobManager subscribes a new sub, eventStr=event_readyToInitializeNetworkEventsDevToolsHandler
Trace Severity level: Information, Message: 21:11:53 (4888): Created new dev tools registration factory
Trace Severity level: Information, Message: 21:11:53 (4888): Created new lifespan handler
Trace Severity level: Information, Message: 21:11:53 (4888): Destroying Cef proxy event handler
Trace Severity level: Information, Message: 21:11:53 (4888): Assigning Cef proxy controller stream provider...
Trace Severity level: Information, Message: 21:11:53 (4888): Initializing Cef proxy controller
Trace Severity level: Information, Message: 21:11:53 (4888): Using subprocess path 'C:\home\site\wwwroot\bin\runtimes\win-x64\native\IronCefSubprocess.exe'
Trace Severity level: Information, Message: 21:11:53 (4888): Using framework path 'C:\home\site\wwwroot\bin\runtimes\win-x64\native'
Trace Severity level: Information, Message: 21:11:53 (4888): Using locales path 'C:\home\site\wwwroot\bin\runtimes\win-x64\native\locales'
Trace Severity level: Information, Message: 21:11:53 (4888): Using resources path 'C:\home\site\wwwroot\bin\runtimes\win-x64\native'
Trace Severity level: Information, Message: 21:11:53 (4888): Launching child process '"C:\Windows\system32\inetsrv\w3wp.exe" -ap -v -a -h -w -m -t -ta --browser-subprocess-path="C:\home\site\wwwroot\bin\runtimes\win-x64\native\IronCefSubprocess.exe" --no-sandbox --lang=en-US --log-file=cef.log --log-severity=disable --resources-dir-path="C:\home\site\wwwroot\bin\runtimes\win-x64\native" --locales-dir-path="C:\home\site\wwwroot\bin\runtimes\win-x64\native\locales" --disable-features=CalculateNativeWinOcclusion,WinUseBrowserSpellChecker,BackForwardCache MYAZUREFUNCTION v4.0 "\.\pipe\iisipm955547cf-bd85-45ba-a205-cfc9ce34ab42" "D:\DWASFiles\Sites\MYAZUREFUNCTION\Config\applicationhost.config" "D:\DWASFiles\Sites\MYAZUREFUNCTION\Config\rootweb.config" 0
Trace 1:11:53.244 PM Trace Severity level: Information, Message: 21:11:53 (4888): gpu_mode: '0'

It looks like it fails on the subprocess launch in the second to last trace, but hard exits without hitting the try catch.

Given this context, I have one question:

What could be causing the IronPdf.ChromePdfRenderer to fail on Azure, despite functioning locally? Any insights or suggestions for troubleshooting this issue would be greatly appreciated.

1

There are 1 best solutions below

1
On BEST ANSWER

Adding this line resolved a similar issue running in App Service:

IronPdf.Installation.SingleProcess = true;

This line forces chrome renderer to perform everything in the current process, rather than using subprocesses. Link to documentation