前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Microsoft ReportViewer 控件类型版本兼容问题及解决方法

Microsoft ReportViewer 控件类型版本兼容问题及解决方法

作者头像
用户1637609
发布2018-04-12 15:20:54
2.7K0
发布2018-04-12 15:20:54
举报
文章被收录于专栏:马洪彪

错误

Parser Error Message: The base class includes the field 'rvEquipment', but its type (Microsoft.Reporting.WebForms.ReportViewer) is not compatible with the type of control (Microsoft.Reporting.WebForms.ReportViewer).

添加引用,因为项目的.Net框架版本是4.0,因此ReportViewer的版本是9.0.

因为使用的开发工具是Visual Studio 2013,因此默认的.Net框架版本是4.5,因此默认的Report Viewer版本是11.0.

此时,程序运行时,会出现版本不兼容的问题。但在错误提示中,显示的是类型不兼容,而它们的类型确实一样的,这就是困扰所在。

解决方法是,在工具箱中添加.Net 4.0的11.0版本的ReportViewer,并使用该控件来显示报表。

此后新建页面,拖入9.0版本的ReportViewer,即可以查看报表。

但是,原来在4.5环境下创建的页面,使用9.0的控件替换11.0的控件后,仍然提示错误。

原因在于,ReportViewer版本的属性,不是在某个控件上指定的,而是在所在的页面中指定的。因此,不能在一个页面中存在两个不同版本的ReportViewer。注册的代码如下:

代码语言:javascript
复制
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

移除该段代码后,重新拖入9.0的控件进行注册。

再次运行,错误提示如下:

Compiler Error Message: CS0433: The type 'Microsoft.Reporting.WebForms.LocalReport' exists in both 'c:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\11.0.0.0__89845dcd8080cc91\Microsoft.ReportViewer.WebForms.DLL' and 'c:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll'

原因在于配置信息中存在两个版本的配置。因此需要删除11.0的配置信息,并把相应的11.0的信息替换为9.0的信息(替换内容为Version和PublicKeyToken)。

web.config配置信息

代码语言:javascript
复制
<?xml version="1.0"?>
<!--
  有关如何配置 ASP.NET 应用程序的详细信息,请访问
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <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.0">
      <assemblies>
        <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="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
      </assemblies>
      <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
      </buildProviders>
    </compilation>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <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>
</configuration>

配置完成后运行,仍然出错,此时问题已经不再是ReportViewer了。因为ReportViewer引用的报表以及数据源等,都存在版本兼容的问题,都需要修改。

综述,使用Visual Studio创建Report Application,版本需要特别注意,需要正确选择.Net框架版本,否则后续移植需要大量的工作。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015-01-22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
腾讯云 BI
腾讯云 BI(Business Intelligence,BI)提供从数据源接入、数据建模到数据可视化分析全流程的BI能力,帮助经营者快速获取决策数据依据。系统采用敏捷自助式设计,使用者仅需通过简单拖拽即可完成原本复杂的报表开发过程,并支持报表的分享、推送等企业协作场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档