开发者

itextsharp "Object reference not set to an instance of an object" error

I have the following code. In my dev enviroment I am not getting any erros but in my production enviroment I do.

...

private Document _pdf;

public Report()
        {
            _pdf = new Document();
        }

public string GenerateReport(string reportType) {
        try {
            var fs = new FileStream("C:\\myfile.pdf", FileMode.Create);
           _pdfWriter = PdfWriter.GetInstance(_pdf, fs);


...

When the code run's I am getting the following error on _pdfWriter = PdfWriter.GetInstance(_pdf, fs);:

Object reference not set to an instance of an object.
    at iTextSharp.text.pdf.PdfWriter.GetInstance(Document document, Stream os)
    at Report.GenerateReport(String reportType)

Why do you think I am getting ths error? The filestream has been created and the _pdf is set in the constructor.

Update

The problem is the _pdf is null. I am not sure why it is null as set in the constructor. I can get round this problem by doing:

if (_pdf ==开发者_如何学编程 null) {
    _pdf = new Document();
}
_pdfWriter = PdfWriter.GetInstance(_pdf, fs);

I would still like to know what I am doing wrong...


The problem was relating to a time out issue on production as there was more data.


I had the same problem when I turned on all exceptions, but you can continue over that exception.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜