如何修复 Visual Studio 2019 中的报表查看器错误?

Man*_*nny 2 asp.net reportviewer rdlc visual-studio

错误:

本地报告处理期间发生错误。
报告“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>
Run Code Online (Sandbox Code Playgroud)

nim*_*bit 12

升级 Microsoft Reports 以支持 Visual Studio 2019 / 2022

运行以下步骤,将使用 Microsoft Report Viewer Runtimes 9-13 的项目升级到 Sql Server Reporting Services 14 或 15。

  1. 备份 Visual Studio 解决方案

  2. 检查是否安装了Visual Studio 2019(最低版本 15.3.1)或Visual Studio 2022(最低版本 17.0.0)的 Microsoft 报表设计器

  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.WebFormsMicrosoft.ReportingServices.ReportViewerControl.Winforms,其中包含更新的 dll

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

Install-Package Microsoft.ReportingServices.ReportViewerControl.WebForms -Version 140.1000.523
Run Code Online (Sandbox Code Playgroud)

ASP.NET - 适用于目标运行时 .NET 4.6 及更高版本 (15.0.0.0)

Install-Package Microsoft.ReportingServices.ReportViewerControl.WebForms -Version 150.1537.0
Run Code Online (Sandbox Code Playgroud)

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

Install-Package Microsoft.ReportingServices.ReportViewerControl.Winforms -Version 140.1000.523
Run Code Online (Sandbox Code Playgroud)

WinForms - 适用于目标运行时 .NET 4.6 及更高版本 (15.0.0.0)

Install-Package Microsoft.ReportingServices.ReportViewerControl.Winforms -Version 150.1537.0
Run Code Online (Sandbox Code Playgroud)

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

  • 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. 在 ASP.NET 中 - App_Code文件夹将具有包含Loader.cs的新SqlServerTypes目录 。并包含包Microsoft.SqlServer.Types.14.0.314.76

此文件夹还将出现在也安装了该包的任何库项目中。

        \SqlServerTypes\
        - Loader.cs or Loader.vb
        - readme.htm
        
        \SqlServerTypes\x64\
        - msvcr120.dll
        - SqlServerSpatial140.dll
        
        \SqlServerTypes\x86\
        - msvcr120.dll
        - SqlServerSpatial140.dll
Run Code Online (Sandbox Code Playgroud)
  1. 如果为 VB.NET 配置了App_Code目录,则应添加一个名为Loader.vb的新 VB 类,并且可以从 App_Code\SqlServerTypes 中删除自动生成的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
    
    Run Code Online (Sandbox Code Playgroud)
  2. 配置

在 ASP.NET 中更新 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>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
      <bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" />
    </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)

或者更新Target .NET 4.6 及更高版本的 Web 配置 (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>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
      <bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" />
    </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
  1. 构建解决方案并确认整个项目已编译。

  2. 如果在旧版本的 Visual Studio 报表设计器中创建报表,请升级报表以支持 Visual Studio IDE。

在 Visual Studio 中双击报表并在提示“您要转换此报表”时进行转换。这会自动将 XML 更新为当前支持的架构。

Microsoft 报表设计器 - 您想要转换此报表吗?

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

然后,当在 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">
Run Code Online (Sandbox Code Playgroud)

至:VS2019 / VS2022

        <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition" 
                xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
                
Run Code Online (Sandbox Code Playgroud)

默认新 VS2019 / VS2022 报告使用什么

        <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" 
                xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
Run Code Online (Sandbox Code Playgroud)

在带有报告参数的报告上

来自: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">
Run Code Online (Sandbox Code Playgroud)

至:VS2019 / VS2022

    <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" 
            xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
Run Code Online (Sandbox Code Playgroud)

如果报表具有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>
Run Code Online (Sandbox Code Playgroud)

如果在提示转换报告时单击“取消”,则可以选择手动编辑架构。

可以编辑 xml 架构并降级支持的规范,以允许在当前版本的 Visual Studio 报表设计器中加载报表。

此版本的 Visual Studio 报表设计器不支持此版本的报表定义语言

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

如果报表是在当前报表设计器不受支持的较新版本中创建的,则升级将会失败。该报告需要降级才能在 Visual Studio 2019 中打开文件。

仅当自动升级失败时,请尝试以下 XML 标记更改;

来自:2016年架构

<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" 
        xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
Run Code Online (Sandbox Code Playgroud)

来自:2016 年架构,包括默认字体系列

<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" 
        xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"
        xmlns:df="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition/defaultfontfamily" 
        MustUnderstand="df">
Run Code Online (Sandbox Code Playgroud)

来自:2010年架构

    <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition" 
            xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
Run Code Online (Sandbox Code Playgroud)

至:2008 架构

    <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" 
            xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
Run Code Online (Sandbox Code Playgroud)

然后通过删除 2008 架构中未使用的元素来降级 SSRS 报告。

删除标签ReportSections但不删除它的任何子元素

<ReportSections></ReportSections>
Run Code Online (Sandbox Code Playgroud)

删除标签ReportSection但不删除它的任何子元素

<ReportSection></ReportSection>
Run Code Online (Sandbox Code Playgroud)

删除元素ReportParametersLayout和所有子元素(包括GridLayoutDefinition

<ReportParametersLayout></ReportParametersLayout>
Run Code Online (Sandbox Code Playgroud)

如果报告包含默认字体属性“df”,还删除以下内容...

删除 Report MustUnderstand="df"属性(如果有)。

删除 Report xmlns:df属性(如果有)。

删除元素df和所有子元素(如果有)。

  1. 对于 WinForms - 在输出目录中包含文件

如果项目是 WinForms,要将报表包含在输出目录中,请右键单击报表文件,然后单击“属性”

将文件属性复制到输出目录更改为“如果较新则复制”并保存项目。

  1. 最后:构建和测试

保存所有更改后,构建解决方案以确认项目是否使用 SQL Server Reporting Services 运行时正确编译,然后使用自定义代码测试处理SSRS 本地报表

为空间数据类型设置 SQL Server 本机程序集

ASP.NET 应用程序 对于 ASP.NET 应用程序,请将以下代码行添加到 Global.asax.cs 中的 Application_Start 方法中:

SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));

桌面应用程序 对于桌面应用程序,请添加以下代码行以在执行任何空间操作之前运行:

SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
Run Code Online (Sandbox Code Playgroud)

报表查看器控制版本

  • 8.0 (2005) - 8.0.50727.42 - Visual Studio 2005

  • 9.0 (2008) - 9.0.30729.1 - Visual Studio 2008

  • 10.0 (2010) - 10.0.40219.1 - Visual Studio 2010

  • 11.0 (2012) - 11.1.3452.0 - Visual Studio 2012/2013

  • 12.0 (2014) 适用于 SQL Server 2014 - 12.0.2000.8 - SQL Server 2014

  • 12.0(2015 报表查看器或使用 SSDT)- 12.0.2402.15 - Visual Studio 2015 (SSDT)

  • SQL Server 2016 的 13.0 (NuGet) - 13.0.1700.305 - SQL Server 2016

  • SQL Server 2016 的 13.0 - 13.0.xx - SQL Server 2016 功能包

  • 14.0 (NuGet) - 14.0.1016.229 - Visual Studio 2017

  • 14.0 (2017 SSDT) - 14.0.xx - Visual Studio 2017 (SSDT)

  • 15.0 (NuGet) - 15.0.1537.0 - Visual Studio 2017/2019/2022

  • 15.0(2017/2019 报表设计器扩展) - 15.0.1322.137 - VS 2017/2019 报表设计器

  • 15.0(2022 报表设计器扩展)- 15.0.1509.0 - VS 2022 报表设计器

  • 哇!!!- 我还没有尝试过这个,但是超出了你们分享这个的范围 - 伙计们,这就是它的完成方式!- 超出了这里的职责范围 - 大力支持!!! (2认同)