Page Report Index out of Range

Posted by: domsinclair on 14 September 2017, 9:35 am EST

  • Posted 14 September 2017, 9:35 am EST

    [activereports_archive]Hi I’m trying my hand at building a page report (as opposed to the section reports I have worked on to date). Data from the report is coming from an old access database. The report is set as fixed page layout At the moment as I test it, it returns one record with the following error:

    [vb]Exception details:

    GrapeCity.ActiveReports.ReportException: An unexpected error occured. Additional information: ‘Index was out of range. Must be non-negative and less than the size of the collection.

    Parameter name: index’ —> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

    Parameter name: index

    at System.ThrowHelper.ThrowArgumentOutOfRangeException()

    at System.Collections.Generic.List`1.get_Item(Int32 index)

    at #ZwA.#qYj.get_Item(Int32 index)

    at #sxA.#7lr.#BGr(Int32 contentPosition)

    at #sxA.#7lr.#CGr()

    at #sxA.#7lr.#Qvf()

    at #sxA.#7lr.Run(LayoutContext context, #e4e spaceManager)

    at #sxA.#l3e.#Rvf(LayoutContext context, #e4e spaceManager)

    at #sxA.#83e.#Rvf(LayoutContext context, #e4e masterSpaceManager)

    at #sxA.#93e.Run(LayoutContext context, #e4e spaceManager)

    at #sxA.#93e.#Xyf(LayoutContext context)

    at #sxA.#93e.#Dxf(#S2e masterTree)

    at #sxA.#93e.BuildLayout()

    at #sxA.#rX.BuildLayout(LayoutInfo layoutInfo)

    at #GPr.#RLf.#NNf(IReport report, TargetDeviceCapabilities targetDevice, LayoutNotificationCallback callback)

    at GrapeCity.ActiveReports.Export.Image.Page.ImageRenderingExtension.Render(IReport report, StreamProvider streams, NameValueCollection settings)

    at GrapeCity.ActiveReports.Document.PageDocument.Render(IRenderingExtension renderingExtension, StreamProvider streams, NameValueCollection settings, Boolean forceDataRefresh)

    — End of inner exception stack trace —

    at GrapeCity.ActiveReports.Document.PageDocument.Render(IRenderingExtension renderingExtension, StreamProvider streams, NameValueCollection settings, Boolean forceDataRefresh)

    at GrapeCity.ActiveReports.Viewer.Win.Rdlx.RdlReport.c__DisplayClassf.b__b()

    at GrapeCity.ActiveReports.Viewer.Win.AsyncLoader.c__DisplayClass7.#cAz(Object , DoWorkEventArgs )

    at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)

    at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)[/vb]

    I do have some script in the report in the form of a function to format an address properly (taking as parameters fields from the report). It is possible that some of the parameters being passed into the function may be NULL, could this be the cause of this error, or should I be looking elsewhere?

    Regards

    Dom[/activereports_archive]

  • Posted 14 September 2017, 9:35 am EST

    [activereports_archive]Hello Dom,

    Thank you for the question, but unfortunately I will not be able to comment on why you are facing such an error without actually reproducing it at my end.

    It may be possible that parameter value is sent to the function is null because of which the exception is raised. You may try checking if the field value is Null before any processing. You may simply equate parameter to an empty string to do so.

    It would be really helpful if you could share a sample report replicating this issue, I’d be able to help you bettor in narrowing down the cause of this issue?

    In case you wish to Fields and their values in the script, you may also use the GetFields() method.

    More information under the ‘Miscellaneous’ tab on page: http://helpcentral.componentone.com/nethelp/AR7Help/OnlineEn/CommonFunctions.html

    Best Regards,

    Tuhina[/activereports_archive]

  • Posted 14 September 2017, 9:35 am EST

    [activereports_archive]Hi Tuhina

    Thank you for that, I appreciate that it is virtually impossible for you to determine what the cause of an error might be without access to the actual report and its data. Since posting this question I’m pretty sure that It’s connected with Null values. Being able to access field directly in script in section reports makes handling those easier, but I hadn’t actually noticed the GetFields() function which might prove to be very helpful.

    Is there a working sample that ships with AR that shows this in use, or do you happen to have one to hand at your end.

    Many Thanks

    Dom[/activereports_archive]

  • Posted 14 September 2017, 9:35 am EST

    [activereports_archive]Hello Dom,

    Apologies for the time taken at our end.

    Please find attached a sample report which uses GetFields() method and custom code to check if any field value was null/absent.

    1. To check if FieldValue is null or absent following code was used:

      [vb]Public Function GetValue(FieldValue As Object) As String

      Dim ret As String = FieldValue

      If ret Is Nothing Then

      ret = "No value"

      End If

      Return ret

      End Function[/vb]

    2. GetField is used in the following manner:

      Public Function GetValue2(flds As Fields) As String

      If flds(“Field1”).Value = “A” Then

      Return “A was here”

      Else

      Return flds(“Field1”).Value

      End If

    End Function

    And in the Expressions window =Code.GetValue2(GetFields())

    Could you please check the application at your end and see if it works for you?

    Best Regards,

    Tuhina

    [/activereports_archive]

    2014/01/UsingGetFields.zip

  • Posted 28 June 2020, 9:45 pm EST

    The exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked method. Indexing an empty list will always throw an exception. Use a method like Add to append the item to the end of the list, or Insert to place the item in the middle of the list somewhere, etc. You cannot index into a list if that offset doesn’t exist.

    Typically, an ArgumentOutOfRangeException results from developer error. Instead of handling the exception in a try/catch block, you should eliminate the cause of the exception or, if the argument is returned by a method call or input by the user before being passed to the method that throws the exception, you should validate arguments before passing them to the method.

    http://csharp.net-informations.com/collection/list.htm

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels