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 technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.