我有一个使用新运行时版本 3 的 Azure(持久)功能,该功能应该使用 IronPDF 从 URL 生成 PDF。该函数一直失败,并且记录到 Insights 的唯一错误是这样的:
异常:执行函数时出现异常:A_GetPdfDataFromUrl
类型:Microsoft.Azure.WebJobs.Host.FunctionInvocationException
Stack Trace
Microsoft.Azure.WebJobs.Host.FunctionInvocationException:执行函数时出现异常:A_GetPdfDataFromUrl
---> System.Exception:生成 PDF 时出错'https://www.myurl.com'
at .(String ,CefRenderSettings ,CefBrowserSettings )
,位于 IronPdf.Rendering.Abstractions.PdfRenderProxy'2 的 .RenderPdfDocumentFromUri(ChromePdfRenderOptions Options,ChromeHttpLoginCredentials Login,Uri url)
。 IronPdf.Rendering.Abstractions.PdfRenderProxy'2.RenderUrlAsPdf
(String UrlOrPath) 处的 RenderUrlAsPdf (Uri Url )
在 IronPdf.Rendering.Abstractions.PdfRenderProxy'2.<>c__DisplayClass19_0.b__0()
在 System.Threading.Tasks.Task'1.InnerInvoke()
在 System.Threading.Tasks.Task.<>c.<.cctor>b__274_0 (对象 obj)
在 System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(线程 threadPoolThread,ExecutionContext executionContext,ContextCallback 回调,对象状态)
在 System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(线程 threadPoolThread,ExecutionContext executionContext,ContextCallback 回调,对象状态)
在 System.Threading .Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
在 MyFuncs.PdfFunc.GetPdfDataFromUrl(String url) in D:\a\1\s\Funcs\PdfFunc.cs:第 155 行 Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker'2.InvokeAsync(Object instance, Object[ ] 参数)在 C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:
Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync 的第 52 行( C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs 中的 IFunctionInvoker 调用程序、ParameterHelper parameterHelper、CancellationTokenSource timeoutTokenSource、CancellationTokenSource functionCancellationTokenSource、布尔 throwOnTimeout、TimeSpan timerInterval、IFunctionInstance 实例:第 572 行
在 C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host 中的 Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx 实例,ParameterHelper parameterHelper,ILogger 记录器,CancellationTokenSource functionCancellationTokenSource) \Executors\FunctionExecutor.cs:
Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync 的第 518 行(IFunctionInstanceEx 实例,FunctionStartedMessage 消息,FunctionInstanceLogEntry instanceLogEntry,ParameterHelper parameterHelper,ILogger 记录器,CancellationToken cancelToken)在 C:\projects\azure- webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:第 296 行
不幸的是,IronPDF 日志不会在 Azure 中生成,因为当前版本中存在错误,他们表示将在下一个版本中修复。所以在那之前我无法弄清楚为什么这个简单的代码在 Azure 中失败了。
[FunctionName("A_GetPdfDataFromUrl")]
public async Task<byte[]> GetPdfDataFromUrl([ActivityTrigger] string url)
{
IronPdf.License.LicenseKey = "";
IronPdf.Logging.Logger.EnableDebugging = true;
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
ChromePdfRenderer chromePdfRenderer = new ChromePdfRenderer();
var trackReportPdf = chromePdfRenderer.RenderUrlAsPdf(url);
return trackReportPdf.BinaryData;
}