【问题标题】:How do I fix the report viewer error in Visual Studio 2019?如何修复 Visual Studio 2019 中的报表查看器错误?
【发布时间】:2022-06-29 00:44:52
【问题描述】:

错误:

本地报告处理过程中发生错误。
报表“Include\Impresiones\Rport.rdlc”的定义无效。
此报表的定义无效或不受此版本的 Reporting Services 支持。
报表定义可能是使用更高版本的 Reporting Services 创建的,或者包含基于 Reporting Services 架构格式不正确或无效的内容。

详细信息:报表定义具有无法升级的无效目标命名空间“http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition”。

当我有 VS2012 时,我可以毫无问题地对其进行编辑,但现在我更新到 VS2019,当我编辑报告并想在报告查看器中显示它时,我收到了该错误,我该如何解决?

在我的web.config 我有:

<system.web>
    <httpHandlers>
        <add path="Reserved.ReportViewerWebControl.axd" verb="*" 
             type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" validate="false"/>
    </httpHandlers>
    <compilation debug="true" targetFramework="4.5">
        <assemblies>
            <!--<add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>-->
            <add assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        </assemblies>
        <buildProviders>
            <!--<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>-->
            <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
        </buildProviders>
    </compilation>
    <pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID">
        <controls>
            <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit"/>
        </controls>
    </pages>
</system.web>
<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
        <!--<add name="Reserved-ReportViewerWebControl-axd" path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler" resourceType="Unspecified" />-->
        <!--<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>-->
        <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
    </handlers>
</system.webServer>

【问题讨论】:

    标签: asp.net visual-studio rdlc reportviewer


    【解决方案1】:

    执行以下步骤,将项目从 Microsoft Report Viewer Runtime 9-13 升级到 Sql Server Reporting Services 14 或 15

    1. 备份 Visual Studio 解决方案

    2. 检查 Microsoft Report Designer 是否已为 Visual Studio 2019(最低版本 15.3.1)安装

    3. 从项目中卸载或手动删除程序集引用(9.0.0.0、10.0.0.0、11.0.0.0、13.0.0.0)

    • Microsoft.ReportViewer.WebForms

    • Microsoft.ReportViewer.Common

    1. 安装 Microsoft.ReportingServices.ReportViewerControl.WebForms,其中包括更新的 dll

    对于目标运行时 .NET 4.5.2 (14.0.0.0)

    Install-Package Microsoft.ReportingServices.ReportViewerControl.WebForms -Version 140.1000.523
    

    适用于 Target Runtime .NET 4.6 及更高版本 (15.0.0.0)

    Install-Package Microsoft.ReportingServices.ReportViewerControl.WebForms -Version 150.1484.0
    

    这会将以下程序集安装到项目中

    • Microsoft.ReportViewer.Common.dll
    • Microsoft.ReportViewer.DataVisualization.dll
    • Microsoft.ReportViewer.Design.dll
    • Microsoft.ReportViewer.ProcessingObjectModel.dll
    • Microsoft.ReportViewer.WebDesign.dll
    • Microsoft.ReportViewer.WebForms.dll
    • Microsoft.ReportViewer.WinForms.dll
    1. App Code 文件夹将具有包含 Loader.cs 的新 SqlServerTypes 目录。 并包含包 Microsoft.SqlServer.Types.14.0.314.76

           \App_Code\SqlServerTypes\
           - Loader.cs or Loader.vb
           - readme.htm
      
           \App_Code\SqlServerTypes\x64\
           - msvcr120.dll
           - SqlServerSpatial140.dll
      
           \App_Code\SqlServerTypes\x86\
           - msvcr120.dll
           - SqlServerSpatial140.dll
      
    2. 如果App Code目录是VB,需要添加一个新的VB类Loader.vb,并且可以去掉自动生成的Loader.cs。

           Imports System
           Imports System.IO
           Imports System.Runtime.InteropServices
      
           Namespace SqlServerTypes
               Public Class Utilities
      
      
      
                   <DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
                   Public Shared Function LoadLibrary(ByVal libname As String) As IntPtr
      
                   End Function
      
                   Public Shared Sub LoadNativeAssemblies(ByVal rootApplicationPath As String)
                       Dim nativeBinaryPath = If(IntPtr.Size > 4, Path.Combine(rootApplicationPath, "SqlServerTypes\x64\"), Path.Combine(rootApplicationPath, "SqlServerTypes\x86\"))
                       LoadNativeAssembly(nativeBinaryPath, "msvcr120.dll")
                       LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial140.dll")
                   End Sub
      
                   Private Shared Sub LoadNativeAssembly(ByVal nativeBinaryPath As String, ByVal assemblyName As String)
                       Dim path = System.IO.Path.Combine(nativeBinaryPath, assemblyName)
                       Dim ptr = LoadLibrary(path)
      
                       If ptr = IntPtr.Zero Then
                           Throw New Exception(String.Format("Error loading {0} (ErrorCode: {1})", assemblyName, Marshal.GetLastWin32Error()))
                       End If
                   End Sub
               End Class
           End Namespace
      

    更新 Target .NET 4.5.2 (Reporting Services 14.0.0.0) 的 Web 配置

    <?xml version="1.0"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      https://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.5.2">
          <assemblies>
            <!-- All assemblies updated to version 14.0.0.0. -->
            <add assembly="Microsoft.ReportViewer.Common, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.DataVisualization, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.Design, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.ProcessingObjectModel, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.WebDesign, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.WinForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
          </assemblies>
          <buildProviders>
            <!-- Version updated to 14.0.0.0. -->
            <add extension=".rdlc"
              type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
          </buildProviders>
        </compilation>
        <httpRuntime targetFramework="4.5.2"/>
        <httpHandlers>
          <!-- Version updated to 14.0.0.0 -->
          <add path="Reserved.ReportViewerWebControl.axd" verb="*"
            type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"
            validate="false"/>
        </httpHandlers>
      </system.web>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true"/>
        <handlers>
          <!-- Version updated to 14.0.0.0 -->
          <add name="ReportViewerWebControlHandler" verb="*" path="Reserved.ReportViewerWebControl.axd" preCondition="integratedMode"
            type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
        </handlers>
      </system.webServer>
    </configuration>
    

    Update Web config 用于 Target .NET 4.6 及更高版本(Reporting Services 15.0.0.0)

    <?xml version="1.0"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      https://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.6">
          <assemblies>
            <!-- All assemblies updated to version 15.0.0.0. -->
            <add assembly="Microsoft.ReportViewer.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.DataVisualization, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.Design, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.ProcessingObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.WebDesign, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
            <add assembly="Microsoft.ReportViewer.WinForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
          </assemblies>
          <buildProviders>
            <!-- Version updated to 15.0.0.0. -->
            <add extension=".rdlc"
              type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
          </buildProviders>
        </compilation>
        <httpRuntime targetFramework="4.6"/>
        <httpHandlers>
          <!-- Version updated to 15.0.0.0 -->
          <add path="Reserved.ReportViewerWebControl.axd" verb="*"
            type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"
            validate="false"/>
        </httpHandlers>
      </system.web>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true"/>
        <handlers>
          <!-- Version updated to 15.0.0.0 -->
          <add name="ReportViewerWebControlHandler" verb="*" path="Reserved.ReportViewerWebControl.axd" preCondition="integratedMode"
            type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
        </handlers>
      </system.webServer>
    </configuration>
    
    1. 构建解决方案并确认整个项目编译

    2. 如果在旧版本的 Visual Studio 中创建报告,请升级报告以支持 Visual Studio IDE。双击 Visual Studio 中的报表并在提示“是否要转换此报表”时进行转换。这会自动将 XML 更新为当前支持的架构。

    报告升级后,您必须点击保存以完成对报告文件的更改。系统会自动为原始文件制作一个备份副本,并在该位置创建一个新文件。

    然后,当在 XML 编辑器中查看报告时,转换工具将进行以下架构定义更改

    在没有报告参数的报告上

    来自:VS2013

        <Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" 
                xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" 
                xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
    

    致:VS2019

            <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition" 
                    xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
                    
    

    默认的新 VS2019 报告使用什么

            <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" 
                    xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
    

    在带有报告参数的报告上

    来自:VS2013

        <Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" 
                xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" 
                xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
    

    致:VS2019

        <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" 
                xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
    

    如果报告有 ReportParameters 元素,则添加 ReportParametersLayout 块。例如;

          <ReportParametersLayout>
            <GridLayoutDefinition>
              <NumberOfColumns>1</NumberOfColumns>
              <NumberOfRows>1</NumberOfRows>
              <CellDefinitions>
                <CellDefinition>
                  <ColumnIndex>0</ColumnIndex>
                  <RowIndex>0</RowIndex>
                  <ParameterName>Test</ParameterName>
                </CellDefinition>
              </CellDefinitions>
            </GridLayoutDefinition>
          </ReportParametersLayout>
    

    如果在提示转换报告时单击“取消”,则可以选择手动编辑架构。可以编辑 xml 架构并降级支持的规范,以允许在当前版本的 Visual Studio 2019 报表设计器中加载报表。

    从 2016 年或 2010 年降级到 2008 年架构定义的报告

    如果报表是在当前受支持的报表设计器版本的更高版本中创建的,则报表需要为 downgraded,您会遇到指示文件无法升级的错误。

    来自:2010 架构

        <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition" 
                xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
    

    来自:2016 年架构

    <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" 
                xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
    

    收件人:2008 架构

        <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" 
                xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
            
    

    2008 架构不支持以下元素,可以删除块

    <ReportSection></ReportSection>
    <ReportSections></ReportSections>
    <ReportParametersLayout></ReportParametersLayout>
    

    最后:构建和测试 保存所有更改后,构建解决方案以确认项目正在正确编译 SQL Server Reporting Services 运行时,然后使用您的自定义代码测试处理SSRS Local Report

    【讨论】:

      猜你喜欢
      • 2015-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      • 2021-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多