FastReport的Prepare()方法中的对象引用错误

时间:2014-04-23 12:00:57

标签: asp.net nullreferenceexception fastreport

我正在尝试在aspx链接按钮上创建.pdf文件。以下是我的代码:

    protected void lbtnInvoice_Click(object sender, EventArgs e)
    { 
        List<InvoiceView> invoices = GetInvoices();

        FastReport.Utils.Config.WebMode = true;
        Report rep = new Report();
        var path = @"PathToDataFileToBeUsedByReport\Report.Data";
        rep.Load(path);
        rep.RegisterData(invoices, "Invoice", FastReport.Data.BOConverterFlags.AllowFields, 2);

        if (rep.Report.Prepare())    //Exception Thrown here!
        {
            FastReport.Export.Pdf.PDFExport pdfExport = new FastReport.Export.Pdf.PDFExport();
            pdfExport.ShowProgress = false;
            pdfExport.Subject = "Subject";
            pdfExport.Title = "xxxxxxx";
            pdfExport.Compressed = true;
            pdfExport.AllowPrint = true;
            pdfExport.EmbeddingFonts = true;

            MemoryStream strm = new MemoryStream();
            rep.Report.Export(pdfExport, strm);
            rep.Dispose();
            pdfExport.Dispose();
            strm.Position = 0;

            return File(strm, "application/pdf", "report.pdf");
        }
    }

Object reference not set to an instance of an object

上会抛出异常rep.Report.Prepare()

非常感谢任何帮助。

修改:我将rep.Report.Prepare()替换为rep.Prepare()时出现同样的错误,在这种情况下我知道rep不为空。

0 个答案:

没有答案