Could not load file or assembly 'Oracle.DataAc

2019-01-26 07:05发布

问题:

I am building ASP.NET application with C# and I want to connect to oracle database.
I have added reference to Oracle.DataAccess in my application on my 64bit Microsoft Window Server 2008 machine. I also installed ODAC (Oracle Data Access Component) on my machine and Oracle.DataAccess.dll is also present on this path

C:\Windows\Microsoft.NET\assembly\GAC_64\Oracle.DataAccess

but when i'm trying to connect i encounter following error:

Could not load file or assembly 'Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The system cannot find the file specified.

回答1:

As far as I know, the Oracle.DataAccess assembly works only with 32 bits, I also have this kind of problem with 64 bits and it really does not work. My solution was remove the 64bits from GAC and install the 32 bits on GAC. I also remove any .dll file in the bin folder to my application find the assembly on GAC.

There is no problem if your machine and operational system is 64bits, the 32bits version will work fine.

UPDATE

I recommend you take a look at Official Oracle ODP.NET, Managed Driver, that is a better version than Oracle.DataAccess. This Managed Driver does not need the Oracle Client on the machine, and you just need to provide the TNS on the DataSource field of the connection string and it works fine for 32 and 64 bits.



回答2:

You need to install both x64 and x86 versions of Oracle, because something (I think it was Visual Studio) uses the x86 version when debugging.



回答3:

In VS2010, I changed the platform target to x64 and this error message disappear.



回答4:

essentially same error

missing ODP.NET installation components as per last post from me and the other answer participant.

You check the GAC yet?

If you do not see Oracle.xxx folders,

you are not making any headway.

put the correct version and bit of Oracle.DataAccess.dll into the application /BIN folder and make local reference. It solves many problems.



回答5:

To run your website, you must use IIS since visual studio's development server only runs in 32 bit mode.
In IIS application pool, set your application to run in 64 bit. (The setting is in advanced settings)



回答6:

To resolve this error, I set my app pool in IIS to allow 32bit applications. Open up IIS Manager, right click on the app pool, and select Advanced Settings --> set “Enable 32-bit Applications” to True. It's working fine for me.



回答7:

I got the same exception on a c# console app. What solved it for me is to change the platform target to x86. (project properties => build )