繁体   English   中英

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

[英]Azure Function : system.private.corelib : exception while executing function

我正在编写一个用于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:'SWIGExceptionHelper'的类型初始化器引发了异常。Datalogics。 “ PDFL:无法加载DLL'DL150PDFLPINVOKE':找不到指定的模块。(HRESULT的异常:0x8007007E)。”

相同的代码可以很好地用作控制台应用程序。 我在这里想念什么?

如果修复硬编码的文件名仍然无济于事,则该错误听起来像是权限异常。

Azure Functions在App Service上运行,该服务具有用于所有代码的沙箱,不允许进行某些调用。 例如,PDF生成库广泛使用的GDI32。

Azure Web App沙箱中了解更多信息。

感谢您阅读问题并尝试回答。

我发现,即使在添加对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

根据此MS论坛帖子

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM