[英]Azure Function : system.private.corelib : exception while executing function
I am writing a Azure Function for PDF conversion with dependencies on DataLogics PDF conversion and a Nuget package (mlkpwgen) for password generation. 我正在编写一个用于PDF转换的Azure函数,该函数依赖于DataLogics PDF转换和一个用于生成密码的Nuget包(mlkpwgen)。
Functions are 功能是
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;
using System;
using MlkPwgen;
using Datalogics.PDFL;
using System.Diagnostics;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("Function1")]
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
PDFConversion();
string requestBody = new StreamReader(req.Body).ReadToEnd();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
public static string PDFConversion()
{
using (Library lib = new Library())
{
String sInput = @"C:\Users\Kunal\Downloads\Indian Management.pdf";
String sOutput = @"C:\Users\Kunal\Downloads\WatermarkedOutput.pdf";
Document doc = new Document(sInput);
string ownerPassword = PasswordGenerator.Generate(length: 32);
string userPassword = PasswordGenerator.Generate(length: 32);
doc.Secure(PermissionFlags.Print | PermissionFlags.HighPrint, ownerPassword, userPassword);
WatermarkParams watermarkParams = new WatermarkParams();
watermarkParams.Rotation = 45.3f;
watermarkParams.Opacity = 0.15f;
watermarkParams.TargetRange.PageSpec = PageSpec.AllPages;
WatermarkTextParams watermarkTextParams = new WatermarkTextParams();
Color color = new Color(0.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f);
watermarkTextParams.Color = color;
watermarkTextParams.Text = "Centre Code - Unit - 0101";
Font f = new Font("Arial", FontCreateFlags.Embedded | FontCreateFlags.Subset);
watermarkTextParams.Font = f;
watermarkTextParams.FontSize = 80f;
watermarkTextParams.TextAlign = HorizontalAlignment.Center;
doc.Watermark(watermarkTextParams, watermarkParams);
doc.EmbedFonts();
doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput);
Process.Start(@"C:\Users\Kunal\Downloads\WatermarkedOutput.pdf");
return sInput;
}
}
}
}
I am getting the following Exception 我收到以下异常
"System.Private.CoreLib: Exception while executing function: Function1. Datalogics.PDFL: The type initializer for 'Datalogics.PDFL.PDFLPINVOKE' threw an exception. Datalogics.PDFL: The type initializer for 'SWIGExceptionHelper' threw an exception. Datalogics.PDFL: Unable to load DLL 'DL150PDFLPINVOKE': The specified module could not be found. (Exception from HRESULT: 0x8007007E)."
“ System.Private.CoreLib:执行函数时发生异常:Function1。Datalogics.PDFL:'Datalogics.PDFL.PDFLPINVOKE'的类型初始化器引发了异常。Datalogics.PDFL:'SWIGExceptionHelper'的类型初始化器引发了异常。Datalogics。 “ PDFL:无法加载DLL'DL150PDFLPINVOKE':找不到指定的模块。(HRESULT的异常:0x8007007E)。”
The same code works fine as a Console application. 相同的代码可以很好地用作控制台应用程序。 What am I missing here?
我在这里想念什么?
If fixing the hard-coded file names still doesn't help, the error sounds like a permission exception. 如果修复硬编码的文件名仍然无济于事,则该错误听起来像是权限异常。
Azure Functions run on App Service, which has a sandbox for all the code, where some calls are not allowed. Azure Functions在App Service上运行,该服务具有用于所有代码的沙箱,不允许进行某些调用。 Eg GDI32 which is used extensively by PDF generation libraries.
例如,PDF生成库广泛使用的GDI32。
Read more in Azure Web App sandbox . 在Azure Web App沙箱中了解更多信息。
Thanks for reading through the question and trying to answer. 感谢您阅读问题并尝试回答。
I found that even after adding reference to the Datalogics.PDFL.dll, the code was failing. 我发现,即使在添加对Datalogics.PDFL.dll的引用后,代码也会失败。
So i copied all the other dll's into the bin\\debug folder and now the code works fine 所以我将所有其他dll复制到bin \\ debug文件夹中,现在代码可以正常工作了
DL150ACE.dll DL150ACE.dll
DL150AdobeXMP.dll DL150AdobeXMP.dll
DL150AGM.dll DL150AGM.dll
DL150ARE.dll DL150ARE.dll
DL150AXE8SharedExpat.dll DL150AXE8SharedExpat.dll
DL150BIB.dll DL150BIB.dll
DL150BIBUtils.dll DL150BIBUtils.dll
DL150CoolType.dll DL150CoolType.dll
DL150JP2KLib.dll DL150JP2KLib.dll
DL150PDFL.dll DL150PDFL.dll
DL150PDFLPINVOKE.dll DL150PDFLPINVOKE.dll
DL150pdfport.dll DL150pdfport.dll
DL150pdfsettings.dll DL150pdfsettings.dll
DotNETViewerComponent.dll DotNETViewerComponent.dll
Per this MS Forums post : 根据此MS论坛帖子 :
Azure Functions does not provide support for loading native binaries in its current release.
Azure Functions不支持在其当前版本中加载本机二进制文件。 Even if we were able to install this package, you may still encounter errors when those native dlls are loaded during runtime.
即使我们能够安装此软件包,当在运行时加载这些本机dll时,您仍然可能会遇到错误。
So this is expected behavior when trying to call native binaries. 因此,在尝试调用本机二进制文件时,这是预期的行为。 Please contact our Support department if you have any more questions about getting started using the PDF Library.
如果您对开始使用PDF库有更多疑问,请联系我们的支持部门。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.