PdfWriter.GetInstance throws System.NullReferenceException

半城伤御伤魂 提交于 2019-12-18 09:14:05

问题


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);

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: 

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?


回答1:


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.

Change the following setting to verify:

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



来源:https://stackoverflow.com/questions/15833285/pdfwriter-getinstance-throws-system-nullreferenceexception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!