System.NullReferenceException in Run method


03-07-2010, 12:30 PM
Version: AR6  6.0.2250.0 (hotfix 2) although the same problem was present in the non-hotfix version.

rpt.Run(false)  returns:  "A first chance exception of type 'System.NullReferenceException' occurred in ActiveReports6.dll
Additional information: Object reference not set to an instance of an object."

Given the totally useless stack dump that comes from AR error messages. Is there some reason you can't include the name of the object that is null in the error message?  I've had to troubleshoot that error in the past and quite frankly, I was hoping that AR6 had better error logging.  I guess not.

The main report has 12 subreports.  Each of those may have one or more subreports.  The report has 45 subreports in all. All use the same xml and use xml data sources.  Each subreport uses a different recordset patterns.  I can step through the report (run as a .vb not as an rpx) in debug and it makes it all the way thorugh the ReportEnd methods without errors.

So, to isolate the issue, I removed all but the first subreport. Same problem.  When run totally by itself, the report and each of the subreports work fine.Even subreports with their own subreports work OK.  Could it be that having subreports of subreports of subreports is a problem and that including them in the top level is just one too many?  Nope.  Tried that too.  One of the other subreports has 4 layes of subreports and it renders OK.

Essentially, even though I can run subreport 1 without errors, I can't get the following to run:

report 1
  subreport 1
     subreport 2
     subreport 3


In the _ReportStart event, I have:

If oRptConferenceSummary Is Nothing Then
                Me.RptConferenceSummary = New RptConferenceSummary()
                Dim ds2 As New DataDynamics.ActiveReports.DataSources.XMLDataSource()
                ds2.ValidateOnParse = False
                ds2.FileURL = Nothing  'Though shald not write data to disk just to read it back into a report
                ds2.RecordsetPattern = "//ReportData"  'the root element of the XML which does exist in the XML
                ds2.LoadXML(xDoc.OuterXml)  'xDoc is an System.XML.XMLDocument and is used for each of the other 45 subreports as well
                Me.RptConferenceSummary.DataSource = ds2
                Me.SubReportConferenceSummary.Report = Me.RptConferenceSummary
End If

That same code structure is used in each subreport that calls other subreports, so I don't get why it works if they are run as top level reports but not when they are included as subreports within another report.

As a side note, the AR6 conversion utility (original 6.0 version) wiped out all the recorset pattern and FileURL settings when converting from previous versions (AR NET 2.0 in this case) with xml data sources.  If you at least fix that, then you won't have a doubly unhappy customer when they find out their subreports don't work any more either.

Re: System.NullReferenceException in Run method


03-08-2010, 10:23 PM
Hello,

As you have already tested that the subreport of subreport of subreport is not an issue with ActiveReports 6. Using ActiveReports you can create the nested reports. The code you have provided is also correct. So to test your reports could you please provide me your sample?

I also tested the conversation utility of ActiveReports 6 by converting ActiveReports for .Net 2.0 reports to ActiveReports 6 and the settings of RecordsetPattern and FileURL are maintained. Could you please provide me more information to replicate this issue?

Regards,
Ankit Nigam



Re: System.NullReferenceException in Run method


03-13-2010, 10:57 AM
Do to HIPPA and FERPA, I cannot send the actual data, but I am putting together some dummy data along with an app showing how the subreport works on its own but not as a subreport of another report. In case thise is also helpful, here's the exception text:

System.NullReferenceException: Object reference not set to an instance of an object.
   at DDCssLib.StyleSheet.GetRuleByClassName(String className)
   at #Dqb.#Oqb.set_ClassName(String value)
   at DataDynamics.ActiveReports.Label.set_ClassName(String value)
   at DataDynamics.ActiveReports.Label.QuickLoad(BinaryReader binReader)
   at DataDynamics.ActiveReports.ARControl.#Rvb(BinaryReader binReader)
   at DataDynamics.ActiveReports.Section.#kBb(Stream stream)
   at DataDynamics.ActiveReports.Section.#hBb(#oqb data)
   at #mb.#mqb.#vDb()
   at #mb.#vqb.#rEb()
   at #mb.#vqb.#qEb(Page newPage, Single left, Single top, Single right, Single bottom, UInt32 flags, UInt32& status)
   at DataDynamics.ActiveReports.Section.#uBb(#sqb rData)
   at #mb.#mqb.#vDb()
   at #mb.#vqb.#rEb()
   at #mb.#vqb.#qEb(Page newPage, Single left, Single top, Single right, Single bottom, UInt32 flags, UInt32& status)
   at DataDynamics.ActiveReports.Section.#uBb(#sqb rData)
   at #mb.#mqb.#LDb()
   at #mb.#mqb.#SDb(Section section, Int32 insPos)
   at #mb.#mqb.#SDb(Section section)
   at #mb.#vqb.#vEb()
   at #mb.#vqb.#qEb(Page newPage, Single left, Single top, Single right, Single bottom, UInt32 flags, UInt32& status)
   at DataDynamics.ActiveReports.ActiveReport.#4yb()
   at DataDynamics.ActiveReports.ActiveReport.Run(Boolean syncDocument)
   at FFSWeb.UI.MiscWebPublic.RunReport(XmlDocument xDoc, String sOutputFormat, String psReportTemplateLocation, Boolean pbProcessSubReports, Int32 organizationId) in C:\source\Hawthorn\FFSWeb\UI\MiscWebPublic.vb:line 306

Re: System.NullReferenceException in Run method


03-13-2010, 1:46 PM
Here's a sample.  The subreport run in standalone works OK.  When included in a parent report, it fails with the null exception.  I included the entire solution in the attachment.

Re: System.NullReferenceException in Run method


03-13-2010, 1:52 PM
 AnkitN wrote:
I also tested the conversation utility of ActiveReports 6 by converting ActiveReports for .Net 2.0 reports to ActiveReports 6 and the settings of RecordsetPattern and FileURL are maintained. Could you please provide me more information to replicate this issue?


I believe the problem is due to the FileURL not being set.  We don't use FileURLs at all, only the recordsetpattern.  Attempting to set the recordsetpatter w/o setting the FileURL in an XML data source within the report designer within VS 2005 causes it to crash as well.

To duplicate:
1. add code based active report to a project
2. click on the data source icon on the detail header
3. select the XML tab
4. set the recordsetpatter but do not set the fileurl
5. click save.
6. observe VS 2005 crashing.

My guess is that an AR2 rpx file with a recorsetpattern set but w/o a FileURL also causes an error in the conversion but the exception gets caught so it just doesn't fill in the value in the converted report.

Re: System.NullReferenceException in Run method


03-15-2010, 1:51 PM
Hello,

I have modified your sample and now its working fine. The issue was in the RptSubIEPConferenceSummary_ReportEnd event where you were disposing the RptSubIEPStudentHeaderXML and RptSubIEPPlacementOption references.

Regarding the FileURL issue, I would like to inform you that I have tested the mentioned steps with the latest build 6.0.2250.0 of ActiveReports 6 but was not able to reproduce the behavior. Could you please attach a video or detail steps to reproduce the issue at my end?

Regards,
Ankit Nigam

Re: System.NullReferenceException in Run method


03-15-2010, 7:22 PM
 AnkitN wrote:
I have modified your sample and now its working fine. The issue was in the RptSubIEPConferenceSummary_ReportEnd event where you were disposing the RptSubIEPStudentHeaderXML and RptSubIEPPlacementOption references.


Thanks.  I'm slightly confused though.  If an object has a Dispose method, standard operating procedure is to call the Dispose method when done with it.  I believe the AR.NET 2.0 samples show doing just that.  If one doesn't call the dispose and the reports are called thousands upon thousands of times within the application, wouldn't the applications memory requires continue to grow until it ran out of memory?  (Yes, got all the way back to AR 1.0 (not the .NET version) and it used to happen there.  AR.NET 2.0 doesn't appear to have the same problem but calling the dispose method doesn't cause an error either.    So, since the fix was to comment out calling the Dispose method, how do the subreports get disposed?  Does the parent report handle that now behind the scenes whereas it didn't use to in AR.NET 2.0? If so, how?  The report is declared and instantiated in the report start event as a local variable.  How would the parent report even know about it?  Or, does it access the subreport.report.document dispose method when it is finished?

As far as recoding VS 2005 crashing when not setting the FileURL and only setting the RecordsetPattern, do you have any suggestions as to what software to use to record it?

Re: System.NullReferenceException in Run method


03-15-2010, 8:12 PM
Per your documentation here: http://www.datadynamics.com/Help/ActiveReports6/arCONOptimizingActiveReports.html, it is important to call the dispose methods especially for large reports and I'm guessing 45 subreports probably qualifies as a large report.

So, although your solution was to simply comment out the disposing of the subreports, and while that may get it to run if one were generating a single report and then exiting the application, since the app is used by hundreds of concurrent users and never shuts down, I believe it is important to deallocate the memory.  In order to do that, I moved the code that used to be in the report_end method and override the Dispose method instead. It appears to work and still guarantees that all the dispose methods are getting called so that the memory allocated by the subreports will be released. 
e.g.
    Private disposed as boolean = false  'defined as a class variable

    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposed Then
            If (disposing) Then
                If Not oRptSubIEPStudentHeaderXML Is Nothing Then
                    Me.oRptSubIEPStudentHeaderXML.Document.Dispose()
                    oRptSubIEPStudentHeaderXML.Dispose()
                    oRptSubIEPStudentHeaderXML = Nothing
                End If

                If Not oRptSubIEPPlacementOption Is Nothing Then
                    Me.oRptSubIEPPlacementOption.Document.Dispose()
                    oRptSubIEPPlacementOption.Dispose()
                    oRptSubIEPPlacementOption = Nothing
                End If
            End If
            Me.disposed = True
        End If
        MyBase.Dispose(disposing)
    End Sub

One last thing... One the reports that were converted from an older AR.NET version, there is no RptName.designer.vb file but for new reports there is a RptName.designer.vb file which already has an empty (more or less) dispose method.  Normally one does not touch the code in the designer files as they are generated by VS2005 or the add-on (AR6).  Are there times where the dispose is not empty such that it should be in the designer verses being able to be overloaded in the RptName.vb file?

Re: System.NullReferenceException in Run method


03-16-2010, 1:13 AM
Hello,

When we convert the reports from earlier version of ActiveReports to ActiveReports6, both the reportname.vb and the reportname.designer.vb should get converted. Could you send the reportname.vb and the reportname.designer.vb files from the older version where you observe the designer.vb file not to be converted to ActiveREports6?

Regards,
Prantik

Re: System.NullReferenceException in Run method


03-20-2010, 11:54 PM
 PrantikS wrote:
Hello,

When we convert the reports from earlier version of ActiveReports to ActiveReports6, both the reportname.vb and the reportname.designer.vb should get converted. Could you send the reportname.vb and the reportname.designer.vb files from the older version where you observe the designer.vb file not to be converted to ActiveREports6?

Regards,
Prantik


The reports I had that trouble with were ones that were converted from 1.0 to 2.0 to 2.0 .NET to 6.  The 2.0 .NET version didn't have a reportname.designer.vb so maybe it was the previous .NET conversion that had the problem prior to the v6 conversion.  I'll try and send an example I get a chance this week, but right now I'm busy making the modifications to move the dispose from the report_end to the overloaded dispose method for a couple hundred reports.

Thanks for all the help.

Jon (AR user since v1.08.0042)