0

I am getting below error in VS2022:

Could not load file or assembly 'Oracle.DataAccess, Version=4.112.4.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The system cannot find the file specified. C:\Users<project_folder>\Web.Config 206

The line 206 in web.config is:

<add assembly="Oracle.DataAccess, Version=4.112.4.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>

The target framework is 4.0 and I do have Oracle client installed. I do have oracle data access DLL at Oracle_Folder\odp.net\bin\4

I checked the project properties and found that the Oracle DLL is being referred from GAC. enter image description here

GacUTIL command output:

gacutil /l | findstr Oracle.Data
  Policy.4.112.Oracle.DataAccess, Version=4.112.4.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64
  Oracle.DataAccess, Version=4.112.4.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.DataAccess.resources, Version=4.112.4.0, Culture=de, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.DataAccess.resources, Version=4.112.4.0, Culture=es, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.DataAccess.resources, Version=4.112.4.0, Culture=fr, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.DataAccess.resources, Version=4.112.4.0, Culture=it, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.DataAccess.resources, Version=4.112.4.0, Culture=ja, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.DataAccess.resources, Version=4.112.4.0, Culture=ko, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.DataAccess.resources, Version=4.112.4.0, Culture=pt-BR, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.DataAccess.resources, Version=4.112.4.0, Culture=zh-CHS, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Oracle.DataAccess.resources, Version=4.112.4.0, Culture=zh-CHT, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
  Policy.4.112.Oracle.DataAccess, Version=4.112.4.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86

Note that I can run the application directly from IIS. However, when I try to run from VS2022 or VS2017 I am getting above error.

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
TechTurtle
  • 2,667
  • 4
  • 22
  • 31
  • Please don't paste screenshots, use formatted text. See https://meta.stackoverflow.com/q/285551 – Wernfried Domscheit Jan 12 '23 at 15:19
  • 1
    According to your GAC you installed 32-Bit and 64-Bit version of ODP.NET. Did you also install 32-Bit and 64-Bit version of Oracle Client? I guess your IIS is 64-Bit but when you run application in VS then you use 32-Bit. Follow this instruction to install 32-Bit and 64-Bit of Oracle client: https://stackoverflow.com/questions/24104210/badimageformatexception-this-will-occur-when-running-in-64-bit-mode-with-the-32#24120100 or stick to one architecture. – Wernfried Domscheit Jan 12 '23 at 15:28
  • @WernfriedDomscheit I have edited question for GACUtil command and it's output. Thank you. – TechTurtle Jan 12 '23 at 15:29
  • 1
    Try just commenting that line in your web config. All it does, it forces to precompile. If you have it in GAC, it should work without this pre-compillation. If that is not the case, still not working - copy this DLL into your `bin`. If you get "file has incorrect format" at runtime - you just have the wrong version - x64 vs x86. Change to the correct version – T.S. Jan 12 '23 at 15:37
  • *"when I try to run from VS2022 or VS2017 I am getting above error"* - how do you run directly? What is it Asp.net webforms? provide all the details, versions, etc. Are your web.config exactly same on the IIS and project? – T.S. Jan 12 '23 at 15:39
  • @T.S. I have local IIS setup and the solution directory is mapped to that IIS application. It's ASP.NET webforms. Targeting framework 4.0. The web.config is same as the folder is same. – TechTurtle Jan 12 '23 at 15:44
  • @T.S. commenting didn't worked, it shows maximum error reached. Also copying the dll in bin gave error: Object reference not set to an instance of an object. – TechTurtle Jan 12 '23 at 15:46
  • Here is the tip. According to the Microsoft VS does not have the tooling to Run VS WebForms in x64 context. So, you should always develop in x86. But you can deploy in x64 with no build (allow on-fly builds) or pre-build x64. Oh! we still dont' know, is this Web Site Project or Web Application Project - WSP vs WAP. Then again, my question was, do you run in VS IIS Express? I never use any of these, I only use full IIS and then attach to the process there. – T.S. Jan 12 '23 at 16:03
  • "Object reference not set to an instance of an object." is the runtime error. And potentially the key to solving your issue – T.S. Jan 12 '23 at 16:04
  • @T.S. it's web application (ASP.NET + VB.NET) and doesn't run on IIS Express. Object reference error doesn't give any line number. For some reason, now in VS 2017 it give different error - "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS." However, IIS has proper configurations. – TechTurtle Jan 12 '23 at 17:44
  • @WernfriedDomscheit can you please explain how you infer that I have 32 and 64 bit ODP.NET? Also, how can I check if I have Oracle client with 64 bit? This error is killing me because it working working properly and suddenly started throwing error. – TechTurtle Jan 12 '23 at 17:51
  • This line `Policy.4.112.Oracle.DataAccess, Version=4.112.4.0, ..., processorArchitecture=AMD64` looks like, it was installed but not properly removed afterwards – Wernfried Domscheit Jan 12 '23 at 18:02
  • With [Sigcheck](https://learn.microsoft.com/en-us/sysinternals/downloads/sigcheck) you can check if a programm/DLL is 32 or 64 bit. Try it on a core DLL, e.g. `oci.dll` – Wernfried Domscheit Jan 12 '23 at 18:05
  • To check the DLL run in VS DEV CMD a command `corflags Oracle.DataAccess.dll` how to identify https://cloudblogs.microsoft.com/dynamics365/no-audience/2008/09/11/32-bit-vs-64-bit-crm-sdk-assemblies/ How to identify ORA client? one way - go to installation. Find there .net folder. In there find Oracle.DataAccess.dll and run `corflags`. If the dll there is x64-this is x64 client. Your problem is trivial. It just something in the setup is wrong – T.S. Jan 12 '23 at 18:09
  • @T.S. I would no say, it is trivial. Many people here faced the same problem and there can be several reasons, see https://stackoverflow.com/questions/659341/the-provider-is-not-compatible-with-the-version-of-oracle-client#25412992 – Wernfried Domscheit Jan 12 '23 at 18:37
  • The `Oracle.DataAccess.dll` in Oracle installation folder could be different to the `Oracle.DataAccess.dll` which is installed in the GAC, because Oracle [provides](https://www.oracle.com/database/technologies/dotnet-utilsoft-downloads.html) [various](https://www.oracle.com/database/technologies/odac-downloads.html) [downloads](https://www.oracle.com/database/technologies/odac-nuget-downloads.html) for ODP.NET. Assemblies installed in GAC take precedence over DLL's copied to application folder. – Wernfried Domscheit Jan 12 '23 at 18:50
  • @WernfriedDomscheit I deal with this all the time. But I normalized the build proceedings and the problem mostly does not exist. With Oracle unmanaged dll the key is - to have same version of the client and the .net DLL. Sometimes you might have in GAC one version of DLL and in the client - another. And then it means it will not work. – T.S. Jan 12 '23 at 19:58
  • If you do it properly then you don't deliver any `Oracle.DataAccess.dll` at all to your customer but rely on his/her Oracle installation. With proper settings it works with any version (which fulfills the minimum requirements you defined) – Wernfried Domscheit Jan 12 '23 at 20:31
  • ^^ better yet, start using client-less connection and do deliver the DLL and not have it in the GAC – T.S. Jan 12 '23 at 23:14

0 Answers0