1

My config: Vs2015 / X64 PC / ODP.NET X86

I've wrote a few DLL on 'Any Cpu' mode and I would like to write programs that use this DLLs and that can be work on X64 and X86 machins.

But I referenced "Oracle.DataAccess.dll" in my Dlls then I've a warning 'ProcessorArchitecture=X86' on Oracle DLL.

How can I do (I can install ODP.NET X64 if necessary) ?

thks

Babe59
  • 45
  • 1
  • 9

3 Answers3

1

When you compile your DLL with "x86" then also the Oracle.DataAccess.dll must be the x86 version (i.e. 32 bit version)

When you compile your DLL with "x64" then also the Oracle.DataAccess.dll must be the x64 version (i.e. 64 bit version)

For "AnyCPU" it depends, there is no "AnyCPU" version of Oracle.DataAccess.dll. If your application runs on 64-bit Windows it will run as x64 process - thus also Oracle.DataAccess.dll must be the x64 version. If your application runs on 32-bit Windows it will run as x86 process - thus also Oracle.DataAccess.dll must be the x86 version.

To cut a long story short: architecture of Oracle.DataAccess.dll must be the same as the application, i.e. your DLL.

Follow this instruction to run both in parallel: BadImageFormatException. This will occur when running in 64 bit mode with the 32 bit Oracle client components installed

Update

In your *.csproj, resp. *.vbproj edit your reference to ODP.NET like this:

<Reference Include="Oracle.DataAccess">
  <SpecificVersion>False</SpecificVersion>
  <Private>False</Private>
</Reference>

Attributes like Version=... or processorArchitecture=... are not required. Your application will load the correct Oracle.DataAccess.dll depending on selected architecture and target .NET framework (provided that it is installed properly)

Community
  • 1
  • 1
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • On my devlopment PC, in VS2015, I must add Oracle DLL on project references. Then I must choose an Oracle DLL. Then I must choose between x86 or X64 DLL no ? – Babe59 May 16 '17 at 07:01
  • I follow instruction to install X86 and X64 Oracle Client. It seems good. I've added Oracle.DataAccess reference in my project and modifiy '.csproj'. when I compile in X86 or X64 it's ok but if I use 'Any CPU' I've warning => 'There is a difference between the processor architecture of the "MSIL" generation project and the reference processor architecture "Oracle.DataAccess", "AMD64". This difference can cause runtime problems...' – Babe59 May 16 '17 at 13:22
  • "AnyCPU" is a problem because there is no "AnyCPU" version of `Oracle.DataAccess.dll`. Without knowing the customer Windows version (32/64-bit) you cannot determine. In my application I compile two versions at the same time: ` ` – Wernfried Domscheit May 16 '17 at 14:22
  • Finally I decided to work in X64 (since "AnuCpu" can not work with Oracle). Unfortunately I just realized that I can not use UserControls compiled in X64 in visual studio (these UserControls referencing the Oracle DLL).This means that in my case I have to stay in X86? – Babe59 May 30 '17 at 14:20
0

The easiest solution would be to target x86 - a 64-bit operating system can still load and run 32-bit applications, and so this would mean your app can run on both x86 and x64 machines.

The downside is that your app must run as a 32-bit processes, i.e. your process will have a 4GB maximum address space and cannot load 64-bit assemblies. If you try to load your dll in a 64-bit process (e.g. because IIS hasn't been configured to use a 32-bit app pool) you will get a BadImageFormatException.

If thats not acceptable to you then you could try detecting the process version and dynamically loading the correct assembly as per this Stack Overflow answer

Community
  • 1
  • 1
Justin
  • 84,773
  • 49
  • 224
  • 367
0

All the above mentioned solutions are correct, but I just feel the need to mention Oracle.ManagedDataAcces as it does not care what the bitness is.

dbencs
  • 64
  • 3