【问题标题】:C#: The type 'Microsoft.Reporting.WebForms.ReportViewer' exists in both ReportingServicesWebUserInterface.dll and Microsoft.ReportViewer.WebForms.dllC#:“Microsoft.Reporting.WebForms.ReportViewer”类型存在于 ReportingServicesWebUserInterface.dll 和 Microsoft.ReportViewer.WebForms.dll 中
【发布时间】:2012-06-29 00:03:33
【问题描述】:

在搜索了很多类似的帖子和解决方法后,我决定自己发帖。

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0433: 
The type
    'Microsoft.Reporting.WebForms.ReportViewer' 
exists in both 
    'c:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\reportmanager\Bin\ReportingServicesWebUserInterface.dll'
and
    'c:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll'


更新:

大多数类似的帖子都存在一个问题,即它们的 2 个冲突 DLL 的版本分别为 8.0.0.0 和 9.0.0.0 左右。或者它们位于 TEMPORARY 文件夹中。我不认为我的问题可以通过这样的帖子来解决。

在我们的 ReportServer 上有一个 Report.aspx,它呈现一个报告。我想用我自己的文件替换这个文件,以修改页面布局,如下所示:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="WebApplication._Default" %>

<%@ Register 
    Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms"
    TagPrefix="rsweb" %>

<!DOCTYPE>
<html>
    <head runat="server"></head>
    <body>
        <div>
            <form id="reportform" runat="server">
                <div>
                    <rsweb:ReportViewer
                        ID='ReportViewerRoot'
                        runat='server'
                        ProcessingMode='Remote'
                        Height='100%'
                        Width='100%'
                        AsyncRendering='False'
                        SizeToReportContent='True'
                    />
                </div>
            </form>
        </div>
    </body>
</html>

这需要引用 MS.ReportViewer.WebForms.DLL

我的 Project.csproj 文件有这个:

<Reference Include="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />

我无法卸载 C:\WINDOWS 中的任何 DLL,因为它说它是其他应用程序所必需的。

我也尝试过修改web.config,添加一些dependentAssemnly,但不确定什么有用(对上面提到的版本差异很有用)。

此外,我在 web.config 中有这些行:

<compilation defaultLanguage="c#" debug="false" tempDirectory="C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\RSTempFiles\">
    <assemblies>
        <clear />
        <add assembly="ReportingServicesWebServer" />
    </assemblies>
</compilation>

感谢您的意见。 我期待收到您的建议。

【问题讨论】:

  • 您是否尝试删除其中一个?
  • 我不清楚您是如何解决这个问题的,您尝试过哪些解决方案不起作用?您能否详细说明我们可以重现这种情况的一些步骤?
  • 更新有所帮助,但我仍然不完全确定您的情况。也许 BindingRedirect 将版本 8 的调用重定向到版本 9 会对您有所帮助?
  • 嗨 Jeroen,感谢您的回复。您希望收到什么样的附加信息?你的建议是我已经尝试过的。交易是,它不是关于不同的版本 - 而是具有相同命名空间和类的不同 DLL。 'Bin\ReportingServicesWebUserInterface.dll' 似乎也包含一个 Webforms.ReportViewer。

标签: asp.net reporting-services reportviewer


【解决方案1】:

令人满意的解决方案!

在 aspx 中插入 ReportViewer 对象时,会自动添加 DLL 引用(并指向 GAC WebForms)。我需要这个引用(无法成功手动引用 GAC DLL),然后我删除了 aspx 中的 ReportViewer。另外,我添加了对冲突 DLL ReportingServicesWebUserInterface.DLL 的引用。这会将问题(post 的错误输出)转移到 VS,而不是仅在 SSRS 服务器上。

当添加一个新的 ReportViewer() 时,我会在 VS 中得到错误。

解决方案如下:给不需要的 DLL 一个别名(实际上在代码中不使用它)。这将告诉编译器在使用 WebForms 时不要使用此 DLL。看图

报告.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="MyWebApplication._Default" %>

<!DOCTYPE>

<html>
<head runat="server">
    <title></title>
</head>
<body>
    <div>
    <div style="background-color:Red;width:100px;height:100px;">Hoi</div>
    </div>
    <form id="formID" runat="server">
    test
    </form>
    <div>haha</div>
</body>
</html>


报告.aspx.cs

public partial class _Default : System.Web.UI.Page
{
    ReportViewer ReportViewerRoot;

    protected void Page_Load(object sender, EventArgs e)
    {
        AddRV();
    }

    public void AddRV()
    {
        ReportViewerRoot = new ReportViewer()

        formID.Controls.Add(ReportViewerRoot);

        SetReportViewer();
        SetServerReport();
    }

    public void SetReportViewer()
    {
        ReportViewerRoot.ID = "ReportViewerRoot";
        ReportViewerRoot.ProcessingMode = ProcessingMode.Remote;
    }

    private void SetServerReport()
    {
        ServerReport serverReport = ReportViewerRoot.ServerReport;

        // Set the report server URL and report path
        serverReport.ReportServerUrl = new Uri("http://localhost/reportserver");
        serverReport.ReportPath = Request.QueryString["ItemPath"];
        serverReport.Refresh();
    }
}


参考来源:Extern alias walkthrough

【讨论】:

    【解决方案2】:

    我解决了我的问题 从我的 Web.Config 中删除一个程序集 在我的情况下,第 10 版和第 11 版是一起出现的。 我从 Config 中删除以下代码

     <add assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
    

    【讨论】:

    • 你救了我。非常感谢。我使用 Visual Studio 2017。我在文件配置中为我的版本设置为 11.0.0.0。工作正常。
    【解决方案3】:

    如果您有嵌套的应用程序,可能会发生这种情况的另一个原因。 IE。 App1 中的 App2。

    App1 的 web.config 可能会与 App2 混淆。确保它们没有引用同一程序集的不同版本。

    【讨论】:

      【解决方案4】:

      不在这个答案中,但在下一个答案中我已经提出了令人满意的解决方案! :)


      这个解决方案也确实有效,但在开发周期/可读性/可维护性方面并不令人满意。


      我的 Report.aspx 文件只包含这一行:

      <%@ Page Language="C#" AutoEventWireup="true"
      CodeBehind="Report.aspx.cs" Inherits="WebApplication._Default" %>
      


      我的 Report.aspx.cs 确实包含如下代码:

              HtmlGenericControl body = new HtmlGenericControl();
              HtmlForm form = new HtmlForm();
              ReportViewerRoot = new ReportViewer();
      
              Controls.Add(body);
              body.Controls.Add(form);
              form.Controls.Add(ReportViewerRoot);
      


      我的 ReportManager/Web.config 包含以下附加标签:

      <!-- added enableSessionState -->
      <pages validateRequest="false" enableSessionState="true" />
      
      <httpModules>
          <clear />
          <!-- added -->
          <add name="Session"  type="System.Web.SessionState.SessionStateModule"/>
      </httpModules>
      
      <httpHandlers>
          <!-- added -->
          <add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </httpHandlers>
      


      附: 无论如何,我都无法将 report.aspx 中的 html 代码与 reportviewer(aspx 或 cs)结合起来。 我也不能使用&lt;% AddRV(); %&gt;在aspx中动态添加ReportViewer


      附: Web.config 帮助我解决了这些错误:

      在远程模式下,报表查看器控件需要启用会话状态或指定报表服务器连接信息 配置文件。


      报表查看器 Web 控制 HTTP 处理程序尚未在应用程序的 web.config 文件中注册。添加到 system.web/httpHandlers web.config 文件的部分。

      【讨论】:

        【解决方案5】:

        在 web.config 中包含一个标签dependentAssembly 以强制特定版本:

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

        【讨论】:

          【解决方案6】:

          前往

          HKEY_CLASSES_ROOT\Installer\Assemblies\Global

          搜索程序集并通过右键单击删除整行并选择删除。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-02-29
            • 1970-01-01
            • 1970-01-01
            • 2011-04-02
            • 1970-01-01
            • 2017-01-13
            相关资源
            最近更新 更多