本地报告处理期间发生错误。报告的定义'无效

时间:2014-03-24 04:56:12

标签: asp.net-mvc visual-studio-2012 reporting-services windows-server-2008

我是使用SSRS的新手。我在使用VS 2012的PDF中使用.rdlc文件生成报告。当我尝试设置参数时

ReportParameter param = new ReportParameter(kvp.Key, kvp.Value);
LocalReport.SetParameters(param);

这会引发异常:

  

本地报告处理期间发生错误。报告的定义''无效..无法加载文件或程序集“System.Web,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其中一个依赖项。访问被拒绝。

更多详情:

{Microsoft.Reporting.WebForms.LocalProcessingException: An error occurred during local report processing. ---> Microsoft.Reporting.DefinitionInvalidException: The definition of the report '' is invalid. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Access is denied.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
   at System.AppDomain.CreateAppDomainManager()
   at System.AppDomain.Setup(Object arg)
   at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor)
   at System.AppDomainManager.CreateDomainHelper(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomainManager.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at Microsoft.Reporting.ReportCompiler.CreateCompilationTempAppDomain()
   at Microsoft.Reporting.ReportCompiler.CompileReport(ICatalogItemContext context, Byte[] reportDefinition, Boolean generateExpressionHostWithRefusedPermissions, ControlSnapshot& snapshot)
   --- End of inner exception stack trace ---
   at Microsoft.Reporting.ReportCompiler.CompileReport(ICatalogItemContext context, Byte[] reportDefinition, Boolean generateExpressionHostWithRefusedPermissions, ControlSnapshot& snapshot)
   at Microsoft.Reporting.LocalService.GetCompiledReport(PreviewItemContext itemContext, Boolean rebuild, ControlSnapshot& snapshot)
   at Microsoft.Reporting.LocalService.CompileReport()
   at Microsoft.Reporting.LocalService.Microsoft.Reporting.ILocalProcessingHost.CompileReport()
   at Microsoft.Reporting.WebForms.LocalReport.EnsureExecutionSession()
   --- End of inner exception stack trace ---
   at Microsoft.Reporting.WebForms.LocalReport.EnsureExecutionSession()
   at Microsoft.Reporting.WebForms.LocalReport.SetParameters(IEnumerable1 parameters)
   at Microsoft.Reporting.WebForms.Report.SetParameters(ReportParameter parameter)

我错过了什么。在某些帖子中,建议使用丢失的Microsoft.ReportViewer.PorcessingObjectMode.dll。我做到了,所以我拥有所有必需的dll:

-    Microsoft.ReportViewer.Common.dll
-    Microsoft.ReportViewer.WebForms.dll
-    Microsoft.ReportViewer.ProcessingObjectModel.dll
是的。

我提到了这个post。但我仍然无法完成这件事。

5 个答案:

答案 0 :(得分:2)

就我而言,在本地环境中,报告正在运行,但不在暂存环境中。 原因是,我发布我的代码的文件夹本身没有.rdlc文件。这导致了这个错误。

  1. 现在我将.rdlc文件复制粘贴到相应的暂存文件夹中,然后就可以了。
    1. 在发布应用程序之前,右键单击.rdlc文件并转到属性,然后选择Build Action下的内容。然后发布应用程序并检查文件夹,.rdlc文件将在那里。

    2. 现在将其从您的开发环境移至其他环境。

    3. 希望这可能有助于某人。

答案 1 :(得分:2)

当我将应用程序部署到azure时,我遇到了同样的问题。经过几个小时的调试后,我注意到Microsoft.SqlServer.Types与其他报告dll的版本不同。  因此,您应该确保这些dll版本相同。在Web.config中编辑它们的依赖关系,如下所示

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
        <assemblyIdentity name="Microsoft.ReportViewer.DataVisualization" publicKeyToken="89845dcd8080cc91" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.ReportViewer.Common" publicKeyToken="89845dcd8080cc91" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

答案 2 :(得分:1)

编辑:解决方案似乎是未加载报告定义。它可以通过例如

来完成
var reportStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ReportName.rdlc"); 
localReport.LoadReportDefinition(reportStream);

旧建议 - 此处不适用:

老实说,可能会有不同的事情。 首先,设置参数是特殊的。如果您的项目在.NET 4或更高版本中运行,则报告引擎将在与您的应用程序不同的应用程序域中运行。因此,您必须设置可以使用参数的权限。否则它会拒绝所有参数。

var report = new LocalReport();
report.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted));

另一个问题可能是您在开发计算机上使用的是与部署计算机不同的ReportViewer版本。

答案 3 :(得分:1)

简单的方法,进入

的属性

“。rdlc”文件并将Build Action更改为“Content”

,将“复制到输出目录”复制为“始终复制”,

如果您更改“Microsoft.ReportViewer.WebForms”,“Microsoft.ReportViewer.ProcessingObjectModel”,“Microsoft.ReportViewer.Common”的版本号

确保您进入属性并使特定版本在属性下为true。我们探索了所有的解决方案,最后这个有效。

答案 4 :(得分:0)

对我而言,原因是我没有向项目添加对报告程序集(Microsoft.ReportViewer.*)的引用。

由于某种原因,它在从VS运行时起作用,但运行实际发布的站点会导致此错误。