3

I am looking to make my program more dynamic. I would like it to be able to support an Oracle 10g and an Oracle 11g database with the same program. If I build the program using the .DLL reference for one version then the other fails. Is there a way to use the Oracle.DataAccess.DLL that is already on the computer being installed upon, instead of providing the DLL in my installer?

Thanks in advance.

Sean Anderson
  • 789
  • 1
  • 7
  • 7

3 Answers3

6

SpecificVersion is an attribute that applies only during build time. It was designed to assist if there are multiple versions of an assembly in the build environment; when SpecificVersion is true, it will ensure that you build against and reference the desired version. Once the target assembly is built, however, its references contain the strong name and the version number of the referenced assembly. So, if SpecificVersion is false, it's going to be set to reference whatever was the available version of the reference in the build environment at the time.

"Note that the Specific Version property is only a build-time directive, and it has no effect on the runtime version resolution of the referenced assembly" (http://www.code-magazine.com/article.aspx?quickid=0507041&page=3).

However, you could use version redirection to explicitly annotate that you accept any version. The oldVersion field specifies anything (the version you built against), and the newVersion attribute would specify which one you want to actually link against at runtime.

  <dependentAssembly>
    <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342"/>
    <bindingRedirect oldVersion="1.0.0.0-2.111.9999.9999" newVersion="2.102.2.20"/>
  </dependentAssembly>

(See http://msdn.microsoft.com/en-us/library/7wd6ex19.aspx.)

That dependentAssembly node can be applied to different contexts. One possible context would be in a web.config or app.config as a child of the configuration/runtime/assemblyBinding node.

To answer your particular scenario of supporting both Oracle 10g and 11g? There are two options, the former of which was suggested by the user @BQ:

  1. Deploy only one version of ODP.NET. You should be able to talk to both versions of the database server (10g and 11g) from either version of ODP.NET (10g or 11g). See @BQ's answer below.
  2. If you really need to be able to link to two different assembly versions, you will need to have two different version redirection configurations. In other words, you'd need two app.config files, one of which contains a version redirection to the 10g ODP.NET version and the other to the 11g ODP.NET version.

A few more tips:

  1. Make sure you remove any Oracle-provided publisher policies from the GAC. These take precedence over ones in web/app.config
  2. By default, binding failures are cached, so if the ODP.NET assembly happened to fail binding with the version redirection, you'll need to restart IIS to purge the cached failures.
Matthew Rodatus
  • 1,393
  • 9
  • 18
  • +1 for a great answer, especially with the binding redirect. To the original questioner though, you should be able to hit either a 10g or 11g database with either a 10g or 11g client, as long as you can provide appropriate connection info (TNSNAMES alias, etc.). – BQ. Dec 20 '10 at 19:17
  • @BQ That is a good point! I cited you and added your answer above. – Matthew Rodatus Dec 20 '10 at 19:25
2

If you select the reference in Visual Studio and go to the Properties window (F4 by default), you'll see an option labeled "Specific Version". If you set this to false, the project will accept different versions of the DLL.

Now this doesn't necessarily mean that the project will find the version of the DLL. If it isn't near the .exe (i.e. in the folder, or subfolder) or in the GAC, then you'll have to do some work on your own to load it.

CodingGorilla
  • 19,612
  • 4
  • 45
  • 65
  • When would it be added to the GAC? Is that something I should be doing, or is it something that should be occurring on an install of Oracle? – Sean Anderson Dec 20 '10 at 18:32
  • I'm not sure if the Oracle installer puts it in the GAC or not, but I imagine there are circumstances where it does _not_ put it in the GAC. I know you can do an "XCOPY" style deployment of the ODAC, in which case it would not be in the GAC. You're probably better off just deploying the latest version with your application; even with the v11 DLL's, you won't have any problem using an Oracle 10 server. – CodingGorilla Dec 20 '10 at 18:41
1

See @MattRodatus' excellent answer about using a binding redirect if you need to get your application to support multiple versions of Oracle.DataAccess that might be on a machine you're deploying to.

However, you should be able to access a 10g or an 11g database with either version of the Oracle client installation.

See the @the.jxc's answer at Oracle: Does a 10g oracle client work with an 11g server? for a good synopsis of which clients support which databases.

Community
  • 1
  • 1
BQ.
  • 9,393
  • 3
  • 25
  • 35