Visual Studio更新会破坏iText7吗? [英] Does Visual Studio update break iText7?

查看:84
本文介绍了Visual Studio更新会破坏iText7吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用iText7 7.1.6和Visual Studio 2019时遇到问题.我的程序已经运行了一年,但是刚刚将Visual Studio(社区)从16.6.1更新到了16.6.2版本,我进行了重建无需更改任何内容.现在,当我运行程序时,在PdfFont font = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA);处未设置System,NullReferenceException对象引用未设置为对象异常的实例复制到仍在运行16.6.1的笔记本电脑上的完全相同的解决方案就可以正常运行.可能是由于VS版本造成的吗?知道我可以从哪里开始寻找吗?

I have a problem with iText7 7.1.6 and Visual Studio 2019. My program has been running for a year now, but having just updated Visual Studio (Community) to version 16.6.2 from 16.6.1, I did a rebuild without changing anything. Now, when I run the program, I get a System,NullReferenceException Object reference not set to an instance of an object exception at PdfFont font = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA); The exact same solution copied to my laptop still running 16.6.1 runs just fine. Could it maybe be due to the VS version? Any idea where I can start looking?

        using (PdfDocument pdf = new PdfDocument(new PdfWriter(saveFileDialog1.FileName, new WriterProperties().AddXmpMetadata().SetPdfVersion(PdfVersion.PDF_2_0))))
        {
            PdfDocumentInfo info = pdf.GetDocumentInfo();
            info.SetTitle("Old Info");
            info.SetAuthor("G.F. Whitmarsh");
            using (Document document = new Document(pdf, PageSize.A4, false)) // Don't flush immediately
            {
                try
                {
                    document.SetTopMargin(120f);
                    document.SetBottomMargin(50f);
                    document.SetLeftMargin(50f);

                    MyEventHandler meh = new MyEventHandler();
                    pdf.AddEventHandler(PdfDocumentEvent.END_PAGE, meh);
                    meh.Boat = s;
                    meh.ToWeb = ToWeb.Text;
                    meh.DateToInternet = DateToInternet.Text;

                    PdfFont font = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA); //>>> Here is the exception
                    PdfFont bold = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA_BOLD);

对不起,您的答复很晚.这是堆栈跟踪.我已经尝试过使用最新的iText7,但结果相同.第19行正在使用system.IO; .NET 4.6

Sorry for the late reply. Here is the stack trace. I had already tried with the newest iText7, but the same result. Line 19 is using system.IO; .NET 4.6

    itext.io.dll!iText.IO.Font.FontCache.FontCache()    Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    itext.io.dll!iText.IO.Font.FontProgramFactory.CreateFont(string name, byte[] fontProgram, bool cached)  Unknown
    itext.kernel.dll!iText.Kernel.Font.PdfFontFactory.CreateFont(string fontProgram)    Unknown
>   InfoOld.exe!InfoOld.Form1.PdfButton_Click(object sender, System.EventArgs e) Line 212   C#
    System.Windows.Forms.dll!System.Windows.Forms.Control.OnClick(System.EventArgs e)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Button.OnClick(System.EventArgs e)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs mevent)  Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.ButtonBase.WndProc(ref System.Windows.Forms.Message m)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Button.WndProc(ref System.Windows.Forms.Message m)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam)  Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData)  Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm)   Unknown
    InfoOld.exe!InfoOld.Program.Main() Line 19  C#

iText7 7.1.11 此完整的控制台应用程序可在VS2019 16.6.1下运行,但在VS2019 16.6.2下会崩溃

EDIT 2: iText7 7.1.11 This complete console application runs under VS2019 16.6.1 but crashes under VS2019 16.6.2

using iText.Kernel.Font;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;

namespace TestItext7
{
    class Program
    {
        static void Main()
        {
            using (iText.Kernel.Pdf.PdfDocument pdf = new PdfDocument(new PdfWriter(@"c:\temp\tester.pdf", new WriterProperties().AddXmpMetadata().SetPdfVersion(PdfVersion.PDF_2_0))))
            {
                using (Document document = new Document(pdf, PageSize.A4, false)) // Don't flush immediately
                {
                    document.SetTopMargin(120f);
                    document.SetBottomMargin(50f);
                    document.SetLeftMargin(50f);

                    PdfFont font = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA);
                    PdfFont bold = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.HELVETICA_BOLD);

                    document.Add(new Paragraph("Test Header").SetFont(bold).SetFontSize(10).SetFixedLeading(12));
                    document.Add(new Paragraph("Test Contents").SetFont(font).SetFontSize(10).SetFixedLeading(12));

                    System.Diagnostics.Process.Start(@"c:\temp\tester.pdf");
                }
            }
        }
    }
}

也许这会有所帮助?

Maybe this will help?

推荐答案

我通过卸载Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation对其进行了修复. 将Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation更新为version 3.1.10没有帮助.

I fixed it by uninstalling Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation. Updating Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation to version 3.1.10 did not help.

这篇关于Visual Studio更新会破坏iText7吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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