C#:类型'Microsoft.Reporting.WebForms.ReportViewer'两个ReportingServicesWebUserInterface.dll和Microsoft.ReportViewer.WebForms.dll存在

问题描述:

有找遍了一大堆similair岗位,解决方法,我决定把我自己的职位。

Having searched a whole lot of similair posts, workarounds, I decided to make my own post.

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'



更新:

大多数similair职位有作为,他们的2相冲突的DLL有一个版本8.0.0.0 9.0.0.0和,左右有问题。或者说,他们居住在临时文件夹中。我不认为我的问题可以用similairly这些职位来解决。

Most similair posts have as a problem that their 2 conflicting DLLs have a version 8.0.0.0 and 9.0.0.0, or so. Or that they reside in the TEMPORARY folder. I do not think that my problem can be solved similairly with such posts.

在我们的ReportServer存在一个Report.aspx,这使得一个报告。我想用我自己来替换该文件,修改页面布局,像这​​样:

On our ReportServer there exists a Report.aspx, which renders a report. I want to replace this file with my own, to modify the page layout, like so:

<%@ 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参考

This requires a reference to MS.ReportViewer.WebForms.DLL

我Project.csproj文件中有这样的:

My Project.csproj file has this:

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

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

I was not able to uninstall any DLLs in C:\WINDOWS, because it said it was required for other applications.

我也试图修改web.config中,加入一些dependentAssemnly,但不知道什么是有用的(这是上面提到的版本差异非常有用)。

I have also tried to modify web.config, adding some dependentAssemnly, but not sure what would be useful (It was useful for version differences mentioned above).

另外我在web.config中这些行:

Further I have these lines in 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>

感谢您的输入。
我期待着收到您的建议。

Thank you for your input. I am looking forward to receiving your suggestions.

的令人满意的解决方案!

The satisfying solution!

当在ASPX插入的ReportViewer对象,该DLL引用自动添加(并指向的 GAC的WebForms 的)。我需要这个参考(无法手动引用成功GAC到DLL)的,然后我删除的ReportViewer在ASPX。另外,我引用添加到冲突的DLL的 ReportingServicesWebUserInterface.DLL 的。这会将问题(从后输出错误),以VS,在只有SSRS服务器上代替。

When inserting a ReportViewer object in the aspx, the DLL reference is automatically added (and points to the GAC WebForms). I need this reference (Couldn't succeed manually referencing to GAC DLLs), then I remove the ReportViewer in the aspx. Also, I add the reference to the conflicting DLL ReportingServicesWebUserInterface.DLL. This moves the problem (error output from post) to VS, in stead of only on the SSRS Server.

在添加新的ReportViewer(),我会得到错误的VS

When adding a new ReportViewer() I will get the error in VS.

解决方法如下:给无要求的DLL别名(实际上并没有使用它在code)。这将告诉编译器这个DLL不使用的WebForms时使用。见图片

The solution is as follows: give the none-required DLL an alias (without actually using it in code). This will tell the compiler that this DLL is not to be used when using WebForms. See picture

Report.aspx

Report.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>



Report.aspx.cs


Report.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();
    }
}



参考来源:外部别名演练