提问人:Harleyz 提问时间:11/12/2023 更新时间:11/17/2023 访问量:90
在 Azure 上使用 IronPdf 对 .NET 6.0 Azure 函数应用进行故障排除
Troubleshooting .NET 6.0 Azure Function App with IronPdf on Azure
问:
我在使用弹性高级计划在 Windows 上使用 .NET 6.0 (LTS) Azure 函数应用时遇到问题。我的应用程序在本地运行,但不在 Azure 上运行。我正在遵循 IronSoftware 关于如何在 Azure 上使用 .NET 将 HTML 转换为 PDF 的指南,以及相关 Stack Overflow 帖子中的见解。最初,我考虑使用 .NET 6.0(独立),但由于报告的支持问题而恢复。
这是我所处的位置:
本地开发:应用在 .NET 6.0 上本地运行,但必须将运行时复制到 bin 目录。我不确定此步骤对于发布版本或在 Azure 环境中是必需的,因为它适用于 Azureite 本地存储。
测试:应用在本地按预期工作。
部署:我使用了发布配置文件,禁用了“作为包运行”,并添加了大量日志记录。但是,在运行 Ironsoft 示例中的代码时,应用在 Azure 上失败。
此处失败:
log.LogInformation("About to render pdf...");
ChromePdfRenderer renderer = new ChromePdfRenderer();
using var doc = renderer.RenderUrlAsPdf("https://www.google.com/");
log.LogInformation("finished rendering pdf...");
示例代码:
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);
}
错误详细信息:
类型 | 详 |
---|---|
跟踪 | 严重性级别:信息、消息:输入 PrintPdf API 函数... |
跟踪 | 严重性级别:信息、消息:即将呈现 pdf... |
跟踪 | 严重性级别:信息、消息:---------- Microsoft Windows NT 10.0.20348.0 (C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit\IronSoftware.log) ---------- |
跟踪 | 严重性级别:信息、消息:正在初始化本地 Chrome 客户端... |
跟踪 | 严重性级别:信息、消息:使用部署目录“C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit” |
跟踪 | 严重性级别:信息、消息:使用根路径“C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit”创建候选部署(下载:True) |
跟踪 | 严重性级别:信息、消息:为 win-x64 创建文件夹部署 |
跟踪 | 严重性级别:信息、消息:为 win-x64 创建嵌入式部署 |
跟踪 | 严重性级别:信息、消息:为 IronPdf.Native.Chrome.Windows 创建 nuget 部署 |
跟踪 | 严重性级别:信息、消息:为 IronPdf.Native.Chrome.Windows.Windows 创建 nuget 部署 |
跟踪 | 严重性级别:信息、消息:尝试使用“C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit”部署“Chrome”2023.11.0.20149 |
跟踪 | 严重性级别:信息、消息:无法在路径“C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit”中找到用于部署“C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit”的程序集 |
跟踪 | 严重性级别:信息、消息:IronSoftware.Exceptions.IronSoftwareAssemblyMissingException:无法在“C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit”中找到“IronInterop” |
跟踪 | 严重性级别:信息、消息:在“C:\home\site\wwwroot\bin\runtimes\win-x64\native”中成功找到“IronInterop” |
跟踪 | 严重性级别:信息、消息:确定平台“Windows”v10.0.20348.0 的部署命令 |
跟踪 | 严重性级别:信息、消息:使用“默认”v 的部署说明 |
跟踪 | 严重性级别:信息、消息:尝试加载 Windows 库“C:\home\site\wwwroot\bin\runtimes\win-x64\native\IronInterop.dll” |
跟踪 | 严重性级别:信息、消息:尝试加载 Windows 库“C:\home\site\wwwroot\bin\runtimes\win-x64\native\IronInterop.dll” |
跟踪 | 严重性级别:信息、消息:已从“C:\home\site\wwwroot\bin\runtimes\win-x64\native\IronInterop.dll”成功加载本机库 |
跟踪 | 严重性级别:信息、消息:已从“C:\home\site\wwwroot\bin\runtimes\win-x64\native”成功加载“IronInterop”版本“2023.11.0.20149” |
跟踪 | 严重性级别:信息、消息:使用“C:\home\site\wwwroot\bin\runtimes\win-x64\native”成功部署了“Chrome” |
跟踪 | 严重性级别:信息,消息:初始化操作系统的 Chrome 渲染器名称:Windows,标识符:win,版本:10.0.20348.0,版本名称:,域:Microsoft.Azure.WebJobs.Script.WebHost,线程:.NET 线程池辅助角色,路径:C:\Program Files (x86)\SiteExtensions\Functions\4.27.5\64bit |
跟踪 | 严重性级别:信息、消息:创建新的作业集合资源 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):~ Chrome 渲染器 v2023.11.0.20149~ |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):将 JobManager 注册为 event_readyToInitializeNetworkEventsDevToolsHandler 的发布者 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):[EventRegistry] 为发布者注册event_readyToInitializeNetworkEventsDevToolsHandler |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):IsSingleProcess:0 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建 Cef 代理控制器 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建 Cef 接口 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的生命周期事件 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的负载处理程序 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建了新的呈现处理程序 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的打印处理程序 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的开发工具处理程序 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):JobManager 订阅新的子服务器,eventStr=event_readyToInitializeNetworkEventsDevToolsHandler |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的开发工具注册工厂 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的生存期处理程序 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):分配 Cef 代理控制器事件... |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的生命周期事件 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的负载处理程序 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建了新的呈现处理程序 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的打印处理程序 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的开发工具处理程序 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):JobManager 订阅新的子服务器,eventStr=event_readyToInitializeNetworkEventsDevToolsHandler |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的开发工具注册工厂 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):创建新的生存期处理程序 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):销毁 Cef 代理事件处理程序 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):分配 Cef 代理控制器流提供程序... |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):初始化 Cef 代理控制器 |
跟踪 | 严重性级别:信息、消息:21:11:53 (4888):使用子进程路径“C:\home\site\wwwroot\bin\runtimes\win-x64\native\IronCefSubprocess.exe” |
跟踪 | Severity level: Information, Message: 21:11:53 (4888): Using framework path 'C:\home\site\wwwroot\bin\runtimes\win-x64\native' |
跟踪 | Severity level: Information, Message: 21:11:53 (4888): Using locales path 'C:\home\site\wwwroot\bin\runtimes\win-x64\native\locales' |
跟踪 | Severity level: Information, Message: 21:11:53 (4888): Using resources path 'C:\home\site\wwwroot\bin\runtimes\win-x64\native' |
跟踪 | 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 |
跟踪 | 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.
答:
Based on the details you've provided, there are a few potential causes. The main thing would be that Functions run in a sandbox in Azure and do not natively run on Windows. This sandbox will restrict certain operations required by IronPdf, like launching a subprocess or accessing certain system resources. Several tools allow you to run Functions on your Windows machine, Azure Functions Core Tools, and through the Windows Subsystem for Linux.
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
评论