Friday, May 8, 2009

Reporting Services ReportViewer control in local mode - permissions problem

I implemented solution for generating reports on the server for my sharepoint application. I use reporting Services ReportViewer control.

My first POC worked fine as a windows console application. I generated reports and write results to the file as a HTML

The same logic executed from Sharepoint WebPart caused exception during rendering a report:

byte[] htmlBytes = reportViewer1.LocalReport.Render("HTML4.0", null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);

InnerException: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException
Message="Failed to load expression host assembly. Details: Could not load file or assembly 'expression_host_380e9163b7f3428c8dab16a7f4e9022d, Version=10.8.21022.8, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x80131418)"



The solution for this problem is adding following line before rendering

reportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(System.Reflection.Assembly.GetExecutingAssembly().Evidence);