2

How can I use any available version of an assembly on an ASP .NET page?

For example, I use this tag before adding a Crystal Reports control on a web page on my computer:

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

However, if I install this web page on a computer that has a different version of Crystal Reports, I would have to change the version part of the assembly attribute:

<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

Is there any way I can avoid this by instructing ASP .NET to use the newest available version or specify the minimum required version?

Dileep A
  • 108
  • 1
  • 1
  • 5

4 Answers4

4

Just drop the Version= portion:

<%@ Register Assembly="CrystalDecisions.Web, , Culture=neutral, 
                       PublicKeyToken=692fbea5521e1304"
             Namespace="CrystalDecisions.Web" 
             TagPrefix="CR" %>

However this only works with late binding. If you actually compile any of your assemblies against a specific version of the assembly you will need an assembly binding redirect in your Web.config file.

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="CrystalDecisions.Web"
                  publicKeyToken="692fbea5521e1304"
                  />

        <bindingRedirect oldVersion="10.5.3700.0"
                 newVersion="13.0.2000.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Paul Alexander
  • 30,715
  • 14
  • 93
  • 146
  • I tried that but got an error: `Could not load file or assembly 'CrystalDecisions.Web, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified` – Dileep A Mar 11 '11 at 20:02
  • The error is accurate - you're probably missing one of the dependencies of the specific version that was loaded. This is one of the dangers of ignoring the version. – Paul Alexander Mar 11 '11 at 20:16
  • I have three versions of the assembly in my GAC. They all work fine when I specify a version -- I tried with each version. But it fails without the `version=` portion. According to Process Monitor, w3wp searches for CrystalDecisions.Web.dll and CrystalDecisions.Web.exe only in the /bin folder. It does not seem to look in the GAC. Any way I can fix that? – Dileep A Mar 11 '11 at 21:59
  • Your solution seems to have worked for others with the same question. There could be other issues with Crystal Reports installation on my computer. – Dileep A Mar 14 '11 at 16:42
1

You need to use the assemblyBinding section in your web.config file. See this article.

kprobst
  • 14,949
  • 5
  • 29
  • 52
1

You could just do this:

<%@ Register Assembly="CrystalDecisions.Web, Culture=neutral,
PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

This will allow you load any version.

vcsjones
  • 128,004
  • 28
  • 283
  • 274
0

You need to make sure you download the correct CR version. Since you are using VS 2010, you need to refer to CRforVS_redist_install_64bit_13_0_1.zip (for 64 bit machine) or CRforVS_redist_install_32bit_13_0_1.zip (for 32 bit machine). These two are the redistributable packages. You can download full package as well: CRforVS_13_0_1.exe