在我的一个项目中,我使用SSRS生成Excel和PDF格式的报告。当我通过visual studio运行应用程序时,一切正常。但是当应用程序托管在服务器上时,它会给我随机错误,并显示以下错误消息:
Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Failed to load expression host assembly. Details: Object reference not set to an instance of an object.
以下是生成报告的代码:
Function Export(model As AshDailyReportModel) As ActionResult If ModelState.IsValid Then Try Dim Result As New List(Of AshDailyConsolidatedReportModel) Result = ReportBL.Instance.GetData_ASHDailyConsolidatedReport(model) If (Result.Count > 0) Then Dim localReport As LocalReport = New LocalReport localReport.ReportPath = StringUtility.AshDailyConsolidateReportPath Dim reportDataSource As ReportDataSource = New ReportDataSource(StringUtility.dsAshDailyConsolidateReport, Result) localReport.DataSources.Add(reportDataSource) If (model.ExportType = DBEnum.ExportType.Excel) Then Dim bytes() As Byte Try Dim warnings As Warning() = Nothing Dim streamids As String() = Nothing Dim mimeType As String = Nothing Dim encoding As String = Nothing Dim extension As String = Nothing ' Setup the report viewer object and get the array of bytes Dim viewer As New ReportViewer() viewer.ProcessingMode = ProcessingMode.Local viewer.LocalReport.ReportPath = StringUtility.AshDailyConsolidateReportPath viewer.LocalReport.SetBasePermissionsForSandboxAppDomain(New System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted)) viewer.LocalReport.DataSources.Add(reportDataSource) bytes = viewer.LocalReport.Render("Excel", Nothing, mimeType, encoding, extension, streamids, warnings) Response.Buffer = True Response.Clear() Response.ContentType = StringUtility.ApplicationExcel Response.AddHeader("content-disposition", Convert.ToString((Convert.ToString("attachment; filename=") & Utility.GenerateReportName(StringUtility.AshDailyConsolidateReportName, "xls")))) Response.BinaryWrite(bytes) Response.Flush() Response.Close() Return New EmptyResult() 'Return File(bytes, StringUtility.ApplicationExcel, Utility.GenerateReportName(StringUtility.AshDailyConsolidateReportName, "xls")) Catch ex As Exception tblExceptionLogBL.Instance.Insert("AshDailyReport", "Export2", ex) TempData(StringUtility.ErrorMessage) = "There is some problem while processing your request. Please try again later !!!" End Try Else Dim bytes() As Byte = Utility.ReportToPDF(localReport) Return File(bytes, StringUtility.ApplicationPdf, Utility.GenerateReportName(StringUtility.AshDailyConsolidateReportName, "pdf")) End If Else TempData(StringUtility.ErrorMessage) = StringUtility.Record_Not_Found End If Catch ex As Exception tblExceptionLogBL.Instance.Insert("AshDailyReport", "Export", ex) TempData(StringUtility.ErrorMessage) = StringUtility.Failure_General CustomException.HandleException(ex) End Try Return RedirectToAction("Index") End If Return View("~\Views\AshDailyConsolidateReport\Index.vbhtml", model) End Function
任何人请检查并让我知道,我错过了什么和哪里。另请告诉我是否需要任何与IIS相关的配置。