Oracle .NET Development Requirements

Since the .NET Framework version 4.0 Microsoft depreciated their Oracle data provider. This means only the “ODP.NET” (Oracle Data Provider for .NET) is officially supported for development and deployment of production software.

Oracle does fully support .NET which is good. But unfortunately they have not been able to build an “AnyCPU” release of their data access component. This means processor specific assembly references and Oracle Client installations are required, meaning sometimes both 32bit and 64bit clients must be installed side-by-side (up to 1GB each!).

This problem is especially troublesome for developers producing 64bit compatible code, because the current Visual Studio 2010 is still running mostly 32bit at the core on their 64bit machines, causing difficulty during debugging or unit testing their Oracle code.

The following sections explain the requirements when setting up development or preparing for deployment of .NET solutions with Oracle.

Client Installations

For development, both the X86 and X64 builds of the SAME version of an Oracle client are required. This means you cannot use the latest version when Oracle have not released both the 32bit and 64bit versions yet, e.g. at the time of writing this document a .NET 4 version of 11g namely 11.2.0.1.2 has been released, but cannot be used because references must be resolved to both X86 and X64 from .NET AnyCPU complied code, meaning the older 11.2.0.1.1 must be installed.

For deployment in test or production, the .NET code should be compiled as AnyCPU (complied to run in the native processor architecture) and any IIS web sites configured correctly with the native processor (beware running the wrong version of “aspnet_regiis” will cause 64bit web sites to run as 32bit!). Then only one Oracle Client instance is required, 64bit for X64 machines, 32bit for X86 only machines.

Visual Studio

Visual Studio requires both 64bit and 32bit Oracle Clients, because Unit Tests will run as X86 only but debugging will run as the native processor, which should be X64 as developers must be compiling and testing with the newest processor to ensure compatibility.

Common Mistakes

BadImageFormat exceptions will occur if you attempt to access the wrong Oracle Client version, e.g. AnyCPU client code binding to X86 Oracle.DataAccess.dll but only the 64bit Oracle Client is installed. The same version of Oracle Client is required as the referenced ODP.NET DLL. But the solution is not just to install another Oracle Client, first check in case your AnyCPU code is forced to run in the wrong processor architecture (e.g. IIS web site configured for 32bit on 64bit machine, or a unit test running in Visual Studio).

It will also occur if you accidentally reference the wrong version, for example, install 11g 32bit and 64bit client correctly, but do not set “Specific Version” on the Oracle.DataAccess.dll version then install the .NET 4 ODT with ODAC to test that (the 11.112.1.0 CLR2 references are automatically upgraded to 11.112.1.2 CLR4 but that only exists as X86 currently so it cannot find a X86 Oracle Client on a production X64 server which only as that client processor installed).

Best Practices

To avoid the trouble described in the previous sections, use the following best practices.

Assembly References

The GAC will find the correct processor architecture for your Oracle.DataAccess.dll reference, but you must select the exact version which has both processors installed. The next problem is that sometimes the Oracle Installer does not GAC register the DLLs and upgrade policies. Then finally newer versions on different developer PCs can cause compiled references to be upgraded to a build which does not have both processor releases or is not available in the production environment.

To protect against these risks In Visual Studio, after adding a reference select it, then choose properties to check the setting. Set “Specific Version” true to fix the version across developer PCs, then check that “Copy Local” is false (must be a GAC reference not a “browsed” file path or local project copy).

Installation Standards

To clarify these installation requirements and avoid conflicts during multiple Oracle Client installations or removals, it is recommended that the standard “Oracle Home” target path be formatted as follows:

<drive and path><major version>Client_<processor>

e.g.

C:Oracle11.2.0client_X86

C:Oracle11.2.0client_X64

2 thoughts on “Oracle .NET Development Requirements

  1. This is easily the best post on the internet regarding client/server and development using ODP.NET. There are many ‘gotchas’ and you nailed it =D

Leave a Reply

Your email address will not be published. Required fields are marked *