VS2010中ReportViewer程序集的问题



我正在Web应用程序中使用VisualStudio2010中的ReportViewer 10.0.0.0,它的程序集出现问题。服务器安装了ReportViewer 8.0.0.0和9.0.0.0,我正试图避免安装10.0.0.0版本。

我在想,即使没有安装ReportViewer10 dll,是否也可以在服务器上使用它。我将dll的Build Action属性设置为Content,以便将它们复制到输出bin文件夹中。属性Copy to Output DirectoryDo not copy

如以下错误所示,我的项目正在ReportViewer中查找两个程序集,一个在GAC中,另一个在Temporary ASP.NET Files中。通过搜索,我也发现Temporary ASP.NET Files是在每次请求服务器时重新生成的。

为了解决我的问题,我从Temporary ASP.NET Files中删除了dll,整个应用程序停止工作,这表明我的应用程序使用的是Temporary ASP.NET Files中的dll,而不是GAC或bin文件夹中的dll。我想将我的应用程序设置为使用bin文件夹或Temporary ASP.NET Files中的dll,因为在这些位置,dll的版本是正确的(10.0.0.0)。下面的错误显示GAC中的ReportViewer9 dll和Temporary ASP.NET Files中的ReportViewer 10 dll之间存在冲突。

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.
CS0433: The type 'Microsoft.Reporting.WebForms.ReportViewer' exists in both
'c:\WINDOWSassemblyGAC_MSILMicrosoft.ReportViewer.WebForms9.0.0.0__b03f5f7f11d50a3aMicrosoft.ReportViewer.WebForms.dll' and 'C:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesproject4ec9147fd072b522assemblydl3662a86a109c93d3_afeccc01Microsoft.ReportViewer.WebForms.DLL'
Line 180:
Line 181: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
Line 182: private global::Microsoft.Reporting.WebForms.ReportViewer @__BuildControlReportViewer1() {
Line 183:    global::Microsoft.Reporting.WebForms.ReportViewer @__ctrl;
Line 184: 
Source File: C:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesproject4ec9147fd072b522App_Web_default.aspx.cdcab7d2.dmkwuxko.0.cs 
Line: 182

我的问题通过以下操作得到了解决:

我让我的项目引用dll,但我已经将它们从bin文件夹中删除了。这样,dll就不再在Temporary ASP.NET Files文件夹中重新生成,从而结束了冲突:

 CS0433: The type 'Microsoft.Reporting.WebForms.ReportViewer' exists in both
'c:\WINDOWSassemblyGAC_MSILMicrosoft.ReportViewer.WebForms9.0.0.0__b03f5f7f11d50a3aMicrosoft.ReportViewer.WebForms.dll' and 'C:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesproject4ec9147fd072b522assemblydl3662a86a109c93d3_afeccc01Microsoft.ReportViewer.WebForms.DLL'

报表查看器一直无法正常工作(GAC只有版本8和9的dll)。然后在服务器上安装了Report Viewer 10.0.0.0,这次显示了一个新错误:

    CS0433: The type 'Microsoft.Reporting.WebForms.ReportViewer' exists in both
'c:\WINDOWSassemblyGAC_MSILMicrosoft.ReportViewer.WebForms9.0.0.0__b03f5f7f11d50a3aMicrosoft.ReportViewer.WebForms.dll' and 'c:\WINDOWSassemblyGAC_MSILMicrosoft.ReportViewer.WebForms10.0.0.0__b03f5f7f11d50a3aMicrosoft.ReportViewer.WebForms.dll' 

我觉得奇怪的是,这种冲突发生在不同版本的dll之间,这次的解决方案是将以下标记添加到web.config文件中:

    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v2.0.50727">
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.ReportViewer.WebForms" publicKeyToken="b03f5f7f11d50a3a"/>
    <bindingRedirect oldVersion="9.0.0.0" newVersion="10.0.0.0"/>
  </dependentAssembly>
</assemblyBinding>

完成。它在没有任何冲突的情况下工作,并且可以导出报告。

我的问题已经解决了,但我仍然有一个疑问,我希望有人能帮我解决这个问题:

为什么服务器在不同版本的GAC_MSIL中的两个dll之间发生冲突?服务器不应该只查找我在项目中引用并在Web.config中指定的版本吗?(10.0.0.0)

它与machine.config文件有任何关系吗?

相关内容

最新更新