使用.Net Core 2.0编写的AWS Lambda函数无法加载libdl

时间:2018-05-24 20:34:39

标签: c# amazon-web-services .net-core aws-lambda aspose.pdf

我正在使用Visual Studio 2017,AWS Toolkit for VS2017和AWS Lambda Project .Net Core 2.0模板开发c#lambda函数。我已经成功开发并部署了一些功能。我开发了一个使用Aspose.Net版本18.5的函数。在我的Windows机器上测试时,该函数按预期执行。但是,在AWS Lambda上部署时,我会收到此堆栈跟踪:

One or more errors occurred. (The type initializer for 'Gdip' threw an exception.): AggregateException
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at lambda_method(Closure , Stream , Stream , LambdaContextInternal )

at System.Drawing.SafeNativeMethods.Gdip.GdipCreateMatrix2(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy, IntPtr& matrix)
at \u0006   .\u0002(Single \u0002, Single \u0003, Single \u0005, Single , Single \u0006, Single \u000e, \u000e    \u000f)
at    .\u0002(\u0005    \u0002, \u000f ​  \u0003, \u000e    \u0005, Single , Single \u0006, Boolean \u000e, Int32 \u000f, Boolean \u0002 , Double& \u0003 , Double& \u0005 , \u0002 ​ &  )
at    ..ctor(\u000f ​  \u0002, \u0005    \u0003, \u000f ​  \u0005)
at \u0002   .\u000f     \u0002(\u000f ​  \u0002, \u0005    \u0003, \u000f ​  \u0005,    & )
at \u0006   .\u0002(   & \u0002)
at Aspose.Pdf.Devices.ImageDevice.\u0002(Page \u0002)
at Aspose.Pdf.Devices.PngDevice.Process(Page page, Stream output)
at CreateImagesFromPDF.Function.<FunctionHandler>d__10.MoveNext() in C:\Users\Thomas\source\repos\CreateImagesFromPDF\CreateImagesFromPDF\Function.cs:line 156
Unable to load DLL 'libdl': The specified module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E): DllNotFoundException
at Interop.Libdl.dlopen(String fileName, Int32 flag)
at System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary()
at System.Drawing.SafeNativeMethods.Gdip..cctor()

这里的关键信息似乎是“无法加载DLL'libdl'。研究问题我发现Aspose依赖于System.Drawing.Common,它依赖于Windows上的libdl.dll和Linux上的libdl.so( Lambda执行的地方。显然,在Linux的一些发行版中,这个库是libdl.so.2。如果这是一个普通的应用程序,而不是Lambda函数,答案似乎是从libdl.so.2创建一个符号链接到libdl.so。不幸的是,我不相信Lambda可以使用。如果我在Linux上创建我的Lambda包,我会在包中将libdl.so.2重命名为libdl.so。但是,我我正在使用AWS Toolkit创建软件包,并且不知道如何向其添加该库。我将不胜感激。我将不胜感激。

这是我的源代码:

using (GetObjectResponse response = await S3Client.GetObjectAsync(request))
{
    using (Stream responseStream = response.ResponseStream)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            responseStream.CopyTo(ms);

            using (Document doc = new Document(ms))
            {
                for (int i = 0; i < doc.Pages.Count; i++)
                {
                    string outFile = fileName + "_" + (i + 1).ToString() + ".png";
                    string tmpFile = "/tmp/" + outFile;
                    Page page = doc.Pages[i + 1];

                    using (FileStream imageStream = new FileStream(tmpFile, FileMode.Create))
                    {
                        PngDevice pngDevice;
                        pngDevice = new PngDevice(Convert.ToInt32((double)page.Rect.Width * 4.17), Convert.ToInt32((double)page.Rect.Height * 4.17));
                        pngDevice.Process(page, imageStream);
                        imageStream.Close();

                        var putRequest = new PutObjectRequest
                        {
                            BucketName = s3Event.Bucket.Name,
                            Key = newFolder + outFile,
                            ContentType = "image/png",
                            FilePath = tmpFile
                        };

                        PutObjectResponse resp = await S3Client.PutObjectAsync(putRequest);

                        File.Delete(tmpFile);

                    }
                }
            }
        }
    }
}

代码在“pngDevice.Process(page,imageStream);”这一行失败。

0 个答案:

没有答案