我正在使用 .Net SDK (Core 2.1) 开发 AWS Lambda 项目。我需要在我的项目中使用 iText7。当我想调试项目时抛出异常。
System.IO.FileLoadException: Could not load file or assembly 'itext.kernel, Version=7.1.10.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca'. An operation is not legal in the current state. (Exception from HRESULT: 0x80131509)
at LucidMailing.Function.FunctionHandler(JObject input, ILambdaContext context)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at LucidMailing.Function.FunctionHandler(JObject input, ILambdaContext context)
我在他们的技术支持页面(支持页面)中应用了解决方案,但仍然抛出异常。
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Amazon.Lambda.Core;
using Amazon.S3;
using iText.IO.Font.Constants;
using iText.Kernel.Colors;
using iText.Kernel.Font;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas;
using iText.Kernel.Pdf.Extgstate;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
using iText.License;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public async Task<string> FunctionHandler(JObject input, ILambdaContext context)
{
var s3Response = await this.S3Client.GetObjectAsync(BucketName, GetKey(input["id"].ToString()));
using (Stream responseStream = s3Response.ResponseStream)
{
using (MemoryStream memStream = new MemoryStream())
{
responseStream.CopyTo(memStream);
memStream.Seek(0, SeekOrigin.Begin);
var stream = new MemoryStream();
var writer = new PdfWriter(stream);
PdfDocument pdfDoc = new PdfDocument(new PdfReader(memStream), writer);
Document dc = new Document(pdfDoc);
PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);
PdfName name = new PdfName(dealDoc.FileNameWithoutExtension);
pdfDoc.GetCatalog().GetNameTree(name);
Paragraph paragraph = new Paragraph(dealDoc.CompanyId).SetFont(font).SetFontSize(30);
pdfDoc.GetDocumentInfo().SetTitle(dealDoc.FileName);
PdfExtGState gs1 = new PdfExtGState().SetFillOpacity(0.5f);
// Implement transformation matrix usage in order to scale image
for (int i = 1; i <= pdfDoc.GetNumberOfPages(); i++)
{
PdfPage pdfPage = pdfDoc.GetPage(i);
Rectangle pageSize = pdfPage.GetPageSize();
float x = (pageSize.GetLeft() + pageSize.GetRight()) / 2;
float y = (pageSize.GetTop() + pageSize.GetBottom()) / 2;
PdfCanvas over = new PdfCanvas(pdfPage);
over.SetFillColor(ColorConstants.RED);
over.SaveState();
over.SetExtGState(gs1);
dc.ShowTextAligned(paragraph, x, y, i, TextAlignment.CENTER, VerticalAlignment.MIDDLE, 45f);
over.RestoreState();
}
dc.Close();
return Convert.ToBase64String(stream.ToArray());
}
}
}
关于我如何找出这个 DLL 文件的异常的任何建议?