【问题标题】:An error occurred during local report processing.The definition of the report ' is invalid本地报表处理过程中出错。报表'的定义无效
【发布时间】:2014-05-01 08:02:44
【问题描述】:

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

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。但我仍然无法完成这项工作。

【问题讨论】:

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


【解决方案1】:

第一次出现此错误,定义无效。 当我再次调试时,错误变为:

AspNetCore.Reporting.LocalProcessingException: An error occurred during local report processing.;The process cannot access the file 
'C:\Users\OPTIMUS PRIME\AppData\Local\Temp\b75e496e6c4d453fbf39526dd5952c14.xls.tmp' because it is being used by another process. 
---> System.IO.IOException: The process cannot access the file 'C:\Users\OPTIMUS PRIME\AppData\Local\Temp\b75e496e6c4d453fbf39526dd5952c14.xls.tmp' 
because it is being used by another process. at System.IO.FileSystem.DeleteFile(String fullPath) 
at System.IO.File.Delete(String path) 
at AspNetCore.ReportingServices.Rendering.ExcelRenderer.ExcelGenerator.BIFF8.StructuredStorage.CreateSingleStreamFile(Stream source, String streamName, String clsId, Stream output, Boolean forceInMemory) 
at AspNetCore.ReportingServices.Rendering.ExcelRenderer.Excel.BIFF8.BIFF8Generator.SaveSpreadsheet(Stream outputStream, Stream backgroundImage, UInt16 backgroundImageWidth, UInt16 backgroundImageHeight) 
at AspNetCore.ReportingServices.Rendering.ExcelRenderer.MainEngine.Save(Stream output) 
at AspNetCore.ReportingServices.Rendering.ExcelRenderer.ExcelRenderer.Render(Report report, NameValueCollection reportServerParameters, NameValueCollection deviceInfo, NameValueCollection clientCapabilities, Hashtable& renderProperties, CreateAndRegisterStream createAndRegisterStream) 
--- End of inner exception stack trace --- 
at AspNetCore.Reporting.InternalLocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings) 
at AspNetCore.Reporting.InternalLocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings) 
at AspNetCore.Reporting.InternalLocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings) at AspNetCore.Reporting.LocalReport.Execute(RenderType renderType, Int32 pageIndex, Dictionary`2 parameters, String findString) 
at ProjectName.Controllers.ReportController.ReportBrandingAsync(String Cabang, String DisplayProgram, String Brand, String DateFrom, String DateTo) 
in ProjectDirName\Controllers\ReportController.cs:line 267

我尝试运行:

LocalReport localReport = new LocalReport(path);
localReport.AddDataSource("dsBranding", oResult);
var result = localReport.Execute(RenderType.Excel, extension, parameters, mimeType);

而且因为错误太奇怪了,改了两次但我什么也没做,于是我尝试检查我的磁盘C盘是否已满。

尝试删除一些文件以释放一些空间,并且不更改代码,报告再次正常

【讨论】:

    【解决方案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>
    

    【讨论】:

      【解决方案3】:

      对我来说,这是因为我没有在项目中添加对报告程序集 (Microsoft.ReportViewer.*) 的引用。

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

      【讨论】:

        【解决方案4】:

        简单的方法,进入你的属性

        “.rdlc”文件并将构建操作更改为“内容”

        , Copy To Output Directory to "Copy Always",

        如果您更改了 "Microsoft.ReportViewer.WebForms" 、 "Microsoft.ReportViewer.ProcessingObjectModel" 、 "Microsoft.ReportViewer.Common" 的版本号

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

        【讨论】:

          【解决方案5】:

          在我的情况下,在本地环境中,报告正在工作,但在暂存环境中却没有。 原因是,我发布代码的文件夹本身没有 .rdlc 文件。这导致了这个错误。

          1. 现在我将 .rdlc 文件复制粘贴到相应的暂存文件夹中,它可以正常工作。

          1. 在发布您的应用程序之前,右键单击 .rdlc 文件并转到属性,然后选择 Build Action 下的内容。然后发布应用程序并检查文件夹,.rdlc 文件将在那里。

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

          希望这可能对某人有所帮助。

          【讨论】:

            【解决方案6】:

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

            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 版本与在部署机器上使用的不同。

            【讨论】:

            • 谢谢 Mil。但我仍然无法弄清楚与此有关的问题。
            • 对我来说可能是一个愚蠢的问题,但是您的代码将报告定义(rdlc)读入本地报告对象?示例:var reportStream = System.Reflection.Assembly.GetExecutingAssembly()。 GetManifestResourceStream("ReportName.rdlc"); localReport.LoadReportDefinition(reportStream);
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多