Search code examples
reportviewergac

Referencing Microsoft.ReportViewer.WebForms


I have a reference to these assemblies in my MVC project Microsoft.ReportViewer.WebForms Microsoft.ReportViewer.Common

Version is 11.0 but I set it to SpecificVersion = False and CopyLocal = False

But upon deploying, I keep getting this error:

Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=11.0.0.0,

The available versions in GAC are 10.0 and 12.0 but I thought it should simply load whatever is this (hopefully 12.0 since it's the latest one) since I set CopyLocal to false. What am I doing wrong here? Is there a best practice for this since we don't really know what version will the clients have in their GAC but we want to support both versions.


Solution

  • SpecificVersion = False is only a hint for the compiler. Once compiled, your project is bound to a specific version of that assembly.

    Since different assembly versions could have differences that are not compatible with each other, it is not safe to just pick any available version.

    Solutions:

    • Support just one ReportViewer version
    • Have different projects for different ReportViewer versions
    • Use reflection
    • Use binding redirects