Unable to display report in ReportViewer 2010

Unable to display report in ReportViewer 2010

Old forum URL: forums.lhotka.net/forums/t/10547.aspx


Tous-Citi posted on Thursday, July 21, 2011

I'll just converted all my 3.6 CSLA objects to 4.0.  I'll also converted my Windows application to the 4.0 Net Framework.  For datagrids and list controls everything is working as expected.  However, I'm now struggling with the ReportViewer.  I have taken a simple report that I have built from scratch in VS2010.  My data set is populated correctly.  When attempting to set the data source for the ReportViewer, I get the following error:  An error occurred during local report processing.  Failed to load expression host assembly.  Details:  Attempt by method 'Csla.Core.FieldManager.FieldDatamanager.ForceStaticFieldInit(System.Type); to access field 'Csla.Security.CslaIdentity._forceInit' failed.

I've made sure that the reference to the Microsoft.ReportViewer.WinForms.dll is for Version 10.0.0.0.  Do you have any suggestions.

Tous-Citi replied on Thursday, July 21, 2011

After much hair pulling, I found a solution.  What made this so difficult was a combination of many things and a very poor error message that attempted to incriminate CSLA.  First, when converting the report, I found that I had to create a new report and copy the fields from the "converted" report to the new report.  Second, the datasource and parameters are nicely hidden in the "Report Data" window.  Needed to add parameters and datasource thru the interface.  Finally, I had to add reportViewer.LocalReport.SetBasePermissionsForSandboxAppDomain(permissions); when initializing the report viewer.  Hopefully, this can help someone avoid the many wasted hours.

 

        public override ReportViewer GetReportViewer()
        {
            ReportViewer reportViewer = new ReportViewer();
 
            // Set report viewer attributes
            reportViewer.ProcessingMode = ProcessingMode.Local;
            reportViewer.LocalReport.ReportPath = ApplicationPath + "\\ReportLayout\\Report.rdlc";
            reportViewer.LocalReport.DisplayName = "";
            PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);
            reportViewer.LocalReport.SetBasePermissionsForSandboxAppDomain(permissions);
            reportViewer.LocalReport.SetParameters(BuildReportParameters());
 
            reportViewer.LocalReport.DataSources.Add(
                new ReportDataSource("ReportData", _myReportData));
 
            return reportViewer;
        }

 

kmgbkj replied on Sunday, April 15, 2012

May be you said is a solution,but that dose not solve the original problem.

I have meet the same by three years ,I wondered the report some time is right,some time not,through many times for trying different solution,

if your report is a simple one that dose not have 'Expression' or not use ReportParameter,report processing is ok ,or you get the error.

I get the problem is:

We can't use CslaIdentityBase for base class,use GenericIdentity directly. like this:

       private IBeamPrincipal(IBeamIdentity id)

            : base(new GenericIdentity(id.Name,id.AuthenticationType))

        {

        }

 

Hope this is helpful.

Jaans replied on Monday, October 29, 2012

Thanks Citi - a strange change and even worse error description. Your solution  has helped us in another scenario.

Coincidentally, I've just been pulling my hair out at another issue (though likely related to yours). We have functionality were we print an SSRS report directly, without previewing it. In order to do this we need to "Render" the report to memory and then print it.

It works very well normally, but as soon as I introduce it unto a CSLA environment it fails with the following exception:
"Failed to load expression host assembly. Details: Object reference not set to an instance of an object."

After trying so many different things, I started strip away the CSLA "layers" in an attempt to figure out why it works when not part of a CSLA project. I managed to narrow it down to the the current thread's Principal object which is set when "logging in" with Csla using the SetPrincipal approach.

To confirm, I manually set the current thread's Principal object to the current user and the problem went away. I'm not sure how what or why the SSRS local report engine is so sensitive about the security context of the current thread, but hopefully this post will help someone else in some way.

Jaans

 

Copyright (c) Marimer LLC