gpt4 book ai didi

c# - Azure Function : system. private.corelib:执行函数时出现异常

转载 作者:行者123 更新时间:2023-12-02 23:00:26 24 4
gpt4 key购买 nike

我正在编写一个用于 PDF 转换的 Azure 函数,它依赖于 DataLogics PDF 转换和用于密码生成的 Nuget 包 (mlkpwgen)。

函数是

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;
}
}
}
}

我收到以下异常

"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)."

相同的代码作为控制台应用程序可以正常工作。我在这里缺少什么?

最佳答案

如果修复硬编码文件名仍然没有帮助,则该错误听起来像是权限异常。

Azure Functions 在应用服务上运行,该服务有一个用于所有代码的沙箱,其中不允许某些调用。例如。 GDI32 被 PDF 生成库广泛使用。

了解更多信息Azure Web App sandbox .

关于c# - Azure Function : system. private.corelib:执行函数时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50560781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com