If I create a report book with 10 pages it works fine.But if I try again with 11 pages, It throw exception "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
After deleting all temp files it work for 11 pages
14 Answers, 1 is accepted
Please share the code which you are using to add reports to the report book and access them. If you are using an integer index to access reports in the ReportBook.Reports collection, make sure that the index is less than the size of the collection.
Regards,
Nasko
Telerik
{
sqlParams.Add(new SqlParameter("@EndDate", Convert.ToDateTime(EndDate)));
sqlParams.Add(new SqlParameter("@MinCommentDate", Convert.ToDateTime(startDate)));
DataSet reportBookDataSet = PRSData.FetchDataSet("prs_ReportBook", sqlParams.ToArray(), CommandType.StoredProcedure);
Int32 page = PRSDataAdapter.GetreferralSourceCount();
page = (page / 7) + ((page % 7) > 0 ? 1 : 0);
this.Reports.Add(new CoverPageReport());
this.Reports[this.Reports.Count - 1].DocumentMapText = "Cover Page";
for (int i = 1; i <= page; i++)
{
this.Reports.Add(new NewPatientsByReferralSourceReports(i));
this.Reports[this.Reports.Count - 1].DocumentMapText = "New Patients By Referral Source";
}
page = PRSDataAdapter.GetEventTypeCount();
page = (page / 3) + ((page % 3) > 0 ? 1 : 0);
for (int i = 1; i <= page; i++)
{
this.Reports.Add(new ProcedureActivityTrendAnalysisReport(i));
this.Reports[this.Reports.Count - 1].DocumentMapText = "Procedure Activity Trend Analysis";
}
this.Reports.Add(new ProcedureBillingTrendAnalysisReport());
this.Reports[this.Reports.Count - 1].DocumentMapText = "Procedure Billings Trend Analysis";
}
The issue is not reproducible with the provided code snippet. We will need a runnable demo project to test it locally.
Please debug the application to determine what causes the error. As you mentioned that deleting some temp files resolves the problem, please elaborate in what context you are running the code for generating the ReportBook, and what temp files you refer to.
Regards,
Stef
Telerik
We are seeing similar behavior after upgrading our version of Telerik Reporting. Were you able to determine the cause and implement a fix to the issue?
Regards,
Travis
We are currently investigating the issue based on the provided by you project, but the scenario is not correctly set. The mechanism used for changing the ReportBook object produces different ReportBook objects on each call of the resolver, and initially there are 3 calls for registering the client, the instance and obtaining parameters - on each of these calls the ReportBook object must be the same, and the counter in your examples changes the content.
We will appreciate it if we continue the discussion in your support thread on the same question. If anyone experiencing the same problem has a demo project, please open a support ticket and send it to us for further tests.
Regards,
Stef
Telerik
Please send us the code and where to place it to reproduce the issue. Alternatively, you can open a new support ticket and provide us a sample project.
Regards,
Nasko
Progress Telerik
As Stef mentioned, “initially there are 3 calls for registering the client, the instance and obtaining parameters - on each of these calls the ReportBook object must be the same.” I verified this by determining the AddReports method was called 3 times for each ReportBook generation.
So, I created a static variable just above the ReportBook constructor and initialized it to 0. See image01.jpg. The highlighted code is what was added.
Then, at the end of the AddReports method, I added an if statement that would add another report for each of the 3 calls to AddReports every other time the ReportBook is generated. See image02.jpg. The highlighted code is what was added.
In other words, the first, third, fifth, etc. time the ReportBook is generated the extra report is NOT added and ReportBook example/demo performs as it should. However, the second, fourth, sixth, etc. time the ReportBook is generated, the Index out of Range Exception occurs.
This behavior is related to the service storage. Initially, the report document (ReportBook with n number of reports) is saved in the storage. As the report source doesn't change the storage retrieves the same document instance every time until it expires. When one more report is added to ReportBook.ReportSources, the same document will still be retrieved from its storage which will cause an error due to a different number of reports in ReportBook.ReportSources collection.
Let us know how exactly the reports are added to a ReportBook in your actual project.
Regards,
Katia
Progress Telerik
Hi Katia,
This issue is just now arising for us because we have to meet
a new requirement of running in an Azure, load balanced environment. Instead of trying to move to that environment
with the obsolete ReportViewer, we decided the time to upgrade to the HTML5
ReportViewer was long overdue.
We have an accounting software application, which has 300+
existing reports/sub-reports, all of which were created with the Visual Studio
report designer, having the .cs extension. Essentially, we allow our customers to configure what they want to see
in a report. Based on what they
configure, we add individual reports to a ReportBook. This method works fine with the obsolete
ReportViewer. Now that we have upgraded
to the HTML5 ReportViewer, we are seeing these issues.
A specific example is our General Ledger’s Detail Ledger
report, where customers can select which funds in the account structure to
report on. Because each fund can have N number
of departments, which can also have N number of accounts, the report on one
fund can span several pages. For this type
of report, we put each fund’s report in a ReportBook, which allows the customer
to use the document map to quickly navigate between funds. Again, this method works fine with the
obsolete ReportViewer.
If I’m understanding you correctly, it seems that once any
ReportBook is generated, no other ReportBook can be generated until after the
previous one expires. This seems quite restrictive. I would think that because, as you say, a ReportBook
can have N number of reports in its collection, each generation of a ReportBook
might need to be considered unique.
I will be more than happy to work with anyone on your end to
come to a resolution for this, as moving to an Azure, load balanced environment
is a high priority for us.
I have opened a new support ticket on your behalf. We would continue resolving the particular case in this ticket.
Regards,
Todor
Progress Telerik
The issue was resolved by stopping the report book caching when it is required to change the report book at run-time.
This is an excerpt from my reply in the support thread:
"There is an approach which will force the report book to be generated anew each time it is requested. This should prevent any caching of the report book and any index out of range exceptions. Each document in the cache is identified by its report name (type name or URI) and its parameter values. To stop the report book caching, all you need to do is pass a unique value to a parameter in the report book each time you request to view the report book. This value can be the current date and time, or it could be a new GUID."
Regards,
Nasko
Progress Telerik