We have localized Crystal Reports for each of the three languages we support in our web application. I am in the process of minimizing the amount of reports that we ship with our software by setting the localized report text in the code behind (C# 3.5). Everything seems to be working out fine (for the most part) but there is one interesting issue I am running into. When I attempt to access the subreport and set the text of the text objects I get the following error:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
This error only occurs when using the Crystal Viewer and leaving and returning to the page with the subreport. When I comment out the portion of the code that sets the sub report TextObject text the error does not occur.
I have tried setting the text several ways:
ReportDocument doc = REPORDOC.ReportDocument.OpenSubreport("Return Call - Hold Time 2_0 (CR 8.5).rpt");
TextObject subReportReturnCallHoldTimeSummaryHeader = doc.ReportDefinition.ReportObjects["returnCallHoldTimeSummaryHeader_3"] as TextObject;
TextObject subReportConnectedToAnAgentSummaryHeader = doc.ReportDefinition.ReportObjects["connectedToAnAgentSummaryHeader"] as TextObject;
TextObject subReportMedianHeader = doc.ReportDefinition.ReportObjects["medianHeader"] as TextObject;
TextObject subReportAverageHeader = doc.ReportDefinition.ReportObjects["averageHeader"] as TextObject;
subReportReturnCallHoldTimeSummaryHeader.Text = base.GetLocalResourceObject("returnCallHoldTimeSummaryHeader").ToString();
subReportConnectedToAnAgentSummaryHeader.Text = base.GetLocalResourceObject("connectedToAnAgentSummaryHeader").ToString();
subReportMedianHeader.Text = base.GetLocalResourceObject("medianHeader").ToString();
subReportAverageHeader.Text = base.GetLocalResourceObject("averageHeader").ToString();
and
TextObject subReportReturnCallHoldTimeSummaryHeader = REPORDOC.ReportDocument.Subreports["Return Call - Hold Time 2_0 (CR 8.5).rpt"].ReportDefinition.ReportObjects["returnCallHoldTimeSummaryHeader_3"] as TextObject;
TextObject subReportConnectedToAnAgentSummaryHeader = REPORDOC.ReportDocument.Subreports["Return Call - Hold Time 2_0 (CR 8.5).rpt"].ReportDefinition.ReportObjects["connectedToAnAgentSummaryHeader"] as TextObject;
TextObject subReportMedianHeader = REPORDOC.ReportDocument.Subreports["Return Call - Hold Time 2_0 (CR 8.5).rpt"].ReportDefinition.ReportObjects["medianHeader"] as TextObject;
TextObject subReportAverageHeader = REPORDOC.ReportDocument.Subreports["Return Call - Hold Time 2_0 (CR 8.5).rpt"].ReportDefinition.ReportObjects["averageHeader"] as TextObject;
subReportReturnCallHoldTimeSummaryHeader.Text = base.GetLocalResourceObject("returnCallHoldTimeSummaryHeader").ToString();
subReportConnectedToAnAgentSummaryHeader.Text = base.GetLocalResourceObject("connectedToAnAgentSummaryHeader").ToString();
subReportMedianHeader.Text = base.GetLocalResourceObject("medianHeader").ToString();
subReportAverageHeader.Text = base.GetLocalResourceObject("averageHeader").ToString();
I have an idea of why this is happening but I have NO IDEA how to fix it. Any ideas would be wonderful.