Search code examples
asp.netvisual-studio-2010dllassembliesreportviewer

Problems with ReportViewer assemblies in VS2010


I'm using the ReportViewer 10.0.0.0 from VisualStudio2010 into my Web Application and I'm having problems with it's assemblies. The server have ReportViewer 8.0.0.0 and 9.0.0.0 installed and I'm trying to avoid the installation of the 10.0.0.0 version.

I was thinking if it's possible to use the ReportViewer10 dll's on the server even not having it installed. I set the Build Action property of the dlls to Content for them to be copied to the output bin folder. The property Copy to Output Directory is Do not copy.

As the following error shows, my project is finding two assemblies from ReportViewer, one in the GAC and another in the Temporary ASP.NET Files. Searching, I've discovered too that the Temporary ASP.NET Files are re-generated each request to the server.

Trying to solve my problem, I deleted the dll from the Temporary ASP.NET Files and the whole application stop working, showing that my application was using the dll from the Temporary ASP.NET Files, not from GAC or the bin folder. I want to set my application to use the dll from the bin folder OR the Temporary ASP.NET Files, because in these places the dll is in it's correct version (10.0.0.0). The error below shows a conflict between the ReportViewer9 dlls from GAC and ReportViewer10 dlls from Temporary ASP.NET Files.

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:\\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' and 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\project\4ec9147f\d072b522\assembly\dl3\662a86a1\009c93d3_afeccc01\Microsoft.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:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\project\4ec9147f\d072b522\App_Web_default.aspx.cdcab7d2.dmkwuxko.0.cs 
Line: 182

Solution

  • My problem was solved by doing the following:

    I left the dlls be referenced by my project but I've removed them from the bin folder. This way the dll's stopped being re-generated inside Temporary ASP.NET Files folder, ending the conflict:

     CS0433: The type 'Microsoft.Reporting.WebForms.ReportViewer' exists in both
    'c:\\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' and 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\project\4ec9147f\d072b522\assembly\dl3\662a86a1\009c93d3_afeccc01\Microsoft.ReportViewer.WebForms.DLL'
    

    Report Viewer kept not working, how it was expected to (GAC had only versions 8 and 9 of the dlls). Then the Report Viewer 10.0.0.0 was installed on the server, and this time a new error has shown:

        CS0433: The type 'Microsoft.Reporting.WebForms.ReportViewer' exists in both
    'c:\\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' and 'c:\\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' 
    

    I thought that was strange that this conflict had happened between different versions of the dlls, and this time the solution was to add the following tag to the web.config file:

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

    Done. It worked without any conflict and it was possible to export the reports.

    My problem was solved, but I still have one doubt, and I hope someone help me with this one:

    Why did the server had the conflict between two dll's from GAC_MSIL within different versions? Shouldn't the server look only for the version I've referenced in my project and specified in the Web.config? (10.0.0.0)

    Does it have any relation with the machine.config file?