views:

79

answers:

1

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...

A: 

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

Rupert