PdfWriter.GetInstance抛出System.NullReferenceException [英] PdfWriter.GetInstance throws System.NullReferenceException

查看:1152
本文介绍了PdfWriter.GetInstance抛出System.NullReferenceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用iTextSharp 5.3.4使用以下内容创建PDF文档

I'm trying to create a pdf document using iTextSharp 5.3.4 using the following

Document document = new Document();
FileStream stm = new FileStream(filename, FileMode.Create);
PdfWriter writer = PdfWriter.GetInstance(document, stm);

我收到带有以下堆栈跟踪的System.NullReferenceException:

I'm getting a System.NullReferenceException with the following stack trace:

System.NullReferenceException occurred
HResult=-2147467261
Message=La référence d'objet n'est pas définie à une instance d'un objet.
Source=itextsharp
StackTrace:
   à iTextSharp.text.Version.GetInstance()
InnerException: 

我已经验证文件和stm都不为空,如果我在VS12中选择继续,则会创建文档 - 但是始终抛出异常。
我更新到iTextSharp 5.4.0并且它仍在发生。
我在任何地方找不到任何相关信息 - 任何人都有任何想法?

I've verified that neither document nor stm are null, and if I select "continue" in VS12 the document is created - however the exception is always thrown. I updated to iTextSharp 5.4.0 and it's still occurring. I can't find any information on this anywhere - anyone got any ideas?

推荐答案

确保你不是捕捉所有异常。这个 NullReferenceException 很可能是已经在iTextSharp中捕获和处理的那个,所以你不关心它。

事实你可以继续支持这个理论。

Make sure you are not catching all exceptions. This NullReferenceException can very well be one that is already caught and handled inside iTextSharp, so you don't care about it.
The fact that you can continue supports this theory.

更改以下设置以验证:

调试 - >例外 - >删除Common Language Runtime Exceptions列中Thrown复选框。

Debug -> Exceptions -> Remove the checkbox in the column "Thrown" of "Common Language Runtime Exceptions".

这篇关于PdfWriter.GetInstance抛出System.NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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