Azure函数:system.private.corelib:执行函数时发生异常 [英] Azure Function : system.private.corelib : exception while executing function

查看:462
本文介绍了Azure函数:system.private.corelib:执行函数时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am writing a Azure Function for PDF conversion with dependencies on DataLogics PDF conversion and a Nuget package (mlkpwgen) for password generation.

功能

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:执行函数时发生异常: 功能1. Datalogics.PDFL:用于的类型初始值设定项 "Datalogics.PDFL.PDFLPINVOKE"引发了异常. Datalogics.PDFL: "SWIGExceptionHelper"的类型初始值设定项引发了异常. Datalogics.PDFL:无法加载DLL'DL150PDFLPINVOKE':指定 找不到模块. (来自HRESULT的异常:0x8007007E)."

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

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

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函数在App Service上运行,该服务具有用于所有代码的沙箱,其中不允许进行某些调用.例如. PDF生成库广泛使用的GDI32.

Azure Functions run on App Service, which has a sandbox for all the code, where some calls are not allowed. E.g. GDI32 which is used extensively by PDF generation libraries.

Azure网站中了解更多应用沙箱.

这篇关于Azure函数:system.private.corelib:执行函数时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆