C# Azure函数:system.private.corelib:执行函数时发生异常

C# Azure函数:system.private.corelib:执行函数时发生异常,c#,azure,azure-functions,adobe-pdf-library,C#,Azure,Azure Functions,Adobe Pdf Library,我正在编写一个用于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.

我正在编写一个用于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:执行函数时发生异常: Function1.Datalogics.PDFL:的类型初始值设定项 “Datalogics.PDFL.PDFLPINVOKE”引发了异常。Datalogics.PDFL: “SwigeExceptionHelper”的类型初始值设定项引发异常。 Datalogics.PDFL:无法加载DLL“DL150PDFLPINVOKE”:指定的 找不到模块。(HRESULT异常:0x8007007E)。”


同样的代码也可以作为控制台应用程序使用。我在这里遗漏了什么?

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

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


阅读更多信息。

感谢您通读问题并尝试回答

我发现,即使在添加了对Datalogics.PDFL.dll的引用之后,代码还是失败了

因此,我将所有其他dll复制到bin\debug文件夹中,现在代码工作正常

DL150ACE.dll

DL150AdobeXMP.dll

DL150AGM.dll

DL150ARE.dll

DL150AXE8SharedExpat.dll

DL150BIB.dll

DL150BIBUtils.dll

DL150CoolType.dll

DL150JP2KLib.dll

DL150PDFL.dll

DL150PDFLPINVOKE.dll

DL150pdfport.dll

DL150pdfsettings.dll

DotNETViewerComponent.dll符合以下要求:

Azure函数不支持在其当前版本中加载本机二进制文件。即使我们能够安装此软件包,在运行时加载这些本机DLL时,您仍然可能会遇到错误


因此,在尝试调用本机二进制文件时,这是预期的行为。如果您对开始使用PDF库还有任何疑问,请联系我们的支持部门。

失败的代码行是“使用(库lib=new Library())”