cancel
Showing results for 
Search instead for 
Did you mean: 

Object reference not set to an instance of an object

Former Member
0 Kudos

hi..

im using sap crystal reports 13.0.2000.0 with visual studio 2010..

some time whenever i try to export to pdf or excel etc, im getting this error "Object reference not set to an instance of an object "

..some times it works fine

Accepted Solutions (1)

Accepted Solutions (1)

saurabh_pathak
Active Contributor
0 Kudos

Hi,

Try following code (VB.NET)


   Private rd As ReportDocument
    Private exportPath As String
    Private myDiskFileDestinationOptions As DiskFileDestinationOptions
    Private myExportOptions As ExportOptions

   Public Sub ExportSetup()
        exportPath = "C:\Exported\"

        If Not System.IO.Directory.Exists(exportPath) Then
            System.IO.Directory.CreateDirectory(exportPath)
        End If

        myDiskFileDestinationOptions = New DiskFileDestinationOptions()
        myExportOptions = rd.ExportOptions
        myExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
        myExportOptions.FormatOptions = Nothing
        ConfigureExportToPdf()
    End Sub

    Public Sub ConfigureExportToPdf()
        myExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
        myDiskFileDestinationOptions.DiskFileName = exportPath & "PortableDoc.pdf"
        myExportOptions.DestinationOptions = myDiskFileDestinationOptions
        rd.Export(myExportOptions)
    End Sub

Thanks,

Saurabh

Edited by: Saurabh.Pathak on Jul 28, 2011 3:37 PM

Former Member
0 Kudos

but i have not kept any separate code for export..

i am using built in export options in report viewer..it works fine for some time..

if i wait for 10 or 20 seconds and then try to export then it will show error

"Object reference not set to an instance of an object. "

saurabh_pathak
Active Contributor
0 Kudos

Hi,

Please download the sample application from here

http://wiki.sdn.sap.com/wiki/display/BOBJ/CrystalReportsfor.NETSDK+Samples

& try csharp_web_simplepreviewreport.zip & then export.

Thanks,

Saurabh

0 Kudos

Hello,

Check your post back or form unload or even the form load routines. When you get that message it always is because the report no longer is a valid object. You have likely called a report.dispose or close so now the object no longer exists as the error message indicates.

Don

Former Member
0 Kudos

i have used all what you mentioned..

repdoc.Load(strPath);

Logininfo();

reportQueue.Enqueue(repdoc);

if (reportQueue.Count > 3)

{

((ReportDocument)reportQueue.Dequeue()).Dispose();

}

CrystalReportViewer1.ReportSource = repdoc;

Session["ReportDocument"] = repdoc;

int exportFormatFlags = (int)(CrystalDecisions.Shared.ViewerExportFormats.PdfFormat |

CrystalDecisions.Shared.ViewerExportFormats.ExcelFormat | CrystalDecisions.Shared.ViewerExportFormats.WordFormat |

CrystalDecisions.Shared.ViewerExportFormats.ExcelRecordFormat);

CrystalReportViewer1.AllowedExportFormats = exportFormatFlags;

Session[CommonConstants.constMarketingReportTitle] = null;

}

else

{

ReportDocument doc = (ReportDocument)Session["ReportDocument"];

CrystalReportViewer1.ReportSource = doc;

}

but still sometimes i'll get that error..

Answers (2)

Answers (2)

Former Member
0 Kudos

I am having the same problem and I cannot get around it. I moved the report load into the "try" block where I export the report. I tested the database connection, because I assumed I had to have one in the code in order to load and run the report. The connection works fine because I display the rows that the report would produce and had it been able to perform the export. I'm usong Console.WriteLine to display progress.

Any suggestions or guidance would be most appreciated!

Select Case (extension)
            Case ".pdf"
                Try
                    Console.WriteLine("            : Load The Report")
                    CrReport.Load(CrName)
                    Console.WriteLine("            : Report Loaded")
                    If IsNothing(CrReport) Then
                        Console.WriteLine("            : CrReport IsNothing")
                        Return
                    End If
                    Console.WriteLine("            : Export The Report")
                    CrDiskFileDestinationOptions.DiskFileName = ExName
                    CrExportOptions = CrReport.ExportOptions
                    With CrExportOptions
                        .DestinationOptions = CrDiskFileDestinationOptions
                        .ExportDestinationType = ExportDestinationType.DiskFile
                        .ExportFormatType = ExportFormatType.PortableDocFormat
                    End With
                    CrReport.Export(CrExportOptions)
                Catch rex As CrystalDecisions.CrystalReports.Engine.LoadSaveReportException
                    eMsg = "ESMOASEXPCR :: Error Loading Report:  " + CrName + " : " + rex.Message
                    Console.WriteLine(eMsg)
                    Return

                Catch ex As Exception
                    Console.WriteLine("            : Export Exception: " + ex.Message)
                    Return
                End Try
                '                    CrReport.ExportToDisk(ExportFormatType.PortableDocFormat, ExName)
            Case Else
                eMsg = "             : Invalid Export File Type " + extension
                Console.WriteLine(eMsg)
        End Select
        eMsg = "ESMOASEXPCR :: Report Has Been Exported to " + argv(0) + extension
        Console.WriteLine(eMsg)
        Return

0 Kudos

Hi All,

Got the same problem as stated.

Using Crystal Reports 2010 SP1 with .Net framework 4.0 on Windows XP machine.

When we load a Crystal Report and preview a report using our custom created Crystal Reports Viewer, everything works fine. However, after using the same report with different parameters and launching the preview again, we get the same error:

object reference not set to an instance of an object

The following error is being produced

System.NullReferenceException: Object reference not set to an instance of an object.
   at SAPBusinessObjects.WPF.Viewer.ParameterFieldsInfos..ctor(ParameterFields paramFlds)
   at SAPBusinessObjects.WPF.Viewer.DocumentView.RefreshParameterPanel()
   at SAPBusinessObjects.WPF.Viewer.DocumentView..ctor(ReportDocumentBase doc)
   at SAPBusinessObjects.WPF.Viewer.ReportAlbum.OnCreateNewDocumentViewComplete(CreateNewDocumentArgs args)
   at SAPBusinessObjects.WPF.Viewer.DelegateMarshaler.<>c__DisplayClass6`1.<Invoke>b__4(Object )
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

Exception target site:
Void .ctor(CrystalDecisions.Shared.ParameterFields)
Exception stack trace:
   at SAPBusinessObjects.WPF.Viewer.ParameterFieldsInfos..ctor(ParameterFields paramFlds)
   at SAPBusinessObjects.WPF.Viewer.DocumentView.RefreshParameterPanel()
   at SAPBusinessObjects.WPF.Viewer.DocumentView..ctor(ReportDocumentBase doc)
   at SAPBusinessObjects.WPF.Viewer.ReportAlbum.OnCreateNewDocumentViewComplete(CreateNewDocumentArgs args)
   at SAPBusinessObjects.WPF.Viewer.DelegateMarshaler.<>c__DisplayClass6`1.<Invoke>b__4(Object )
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

This is an error in the components provided by Crystal Reports. Is there any workaround or solution for this problem?

Kind regards,

Pieter Jong

Crystal Advice

http://www.crystaladvice.com

former_member183750
Active Contributor
0 Kudos

In my experience, the error essentially means that the report file has gone out of scope. This will typically, though not always be in when post backs and sessions are used incorrecttly.

Ludek