0

I am getting this error message while trying to connect to an Oracle 11g Database in Visual Studio 2019 (ASP.NET MVC Core):

BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342'. An attempt was made to load a program with an incorrect format

What i am missing?

I am using:

using Oracle.Database.Client

This is the nuget package: Oracle.DataAccess.x86 (version: 2.112.1)

I installed Oracle Database 11g Release 2 Client (11.2.0.1.0) for Microsoft Windows (x32)

I have already made sure the app set to run in 32 bit mode in the IIS console. I still can't figure out why is not working.

Can give me a hand?


BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342'. An attempt was made to load a
> program with an incorrect format
MyApplication.Context.Connection.GetList()
MyApplication.Controllers.ControllerList.Index() in ControllerList.cs
+
            List<MyList> myList= dbContext2.GetList().ToList();
lambda_method244(Closure , object , object[] )
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
JustToKnow
  • 785
  • 6
  • 23
  • could you please provide the full stack trace? check that from which place dll file is loading. you could refer to this link:https://stackoverflow.com/questions/15596834/could-not-load-file-or-assembly-oracle-dataaccess-or-one-of-its-dependencies – Jalpa Panchal Feb 26 '21 at 13:35
  • Hey pal, what do you mean by "full stack trace"?How do i get it? – JustToKnow Feb 26 '21 at 13:37
  • could you please provide the detailed error message? – Jalpa Panchal Feb 26 '21 at 13:43
  • @JalpaPanchal take a look, i have edited my question. Im super lost, Dont know what i am doing wrong :( – JustToKnow Feb 26 '21 at 13:48
  • @JalpaPanchal you there? – JustToKnow Feb 26 '21 at 20:25
  • 1
    I've got your message. If you use NETCORE, I would say don't use the oracle client. It is probably not even compatible. I could be mistaken but... Work with client-less **instant client** connection https://stackoverflow.com/questions/7819861/does-odp-net-require-oracle-client-installation. Install oracle ODAC. And use nuget to install ODP package https://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/ODPNET_Core_get_started/index.html – T.S. Feb 26 '21 at 22:18
  • To add to the above ^^^ the error you might get is because .net core assembly architecture does not match to .net framework client assemblies you referring to – T.S. Feb 26 '21 at 22:20
  • Hey @T.S., thank you very very much for replying to my previous message. I'm a little confused about some things related to x32 and x64 and which one should be used in this case. I'm gonna ask you some questions, can check it out?: 1) which version of ODAC is the one that a i need in order to establish a connection to oracle 11g database?2)x32 or x64? 3)What about the ODP package? – JustToKnow Feb 27 '21 at 01:01
  • @T.S. i'm using Windows 7 x64, i just made sure the app set to run in 32 bit mode in the IIS console. Is it okay? it is necessary to delete the Oracle database client that i just installed? – JustToKnow Feb 27 '21 at 01:08
  • 1
    you need to install one of these https://www.oracle.com/database/technologies/dotnet-odacdeploy-downloads.html you need to get one that is compatible to your Oracle DB. if your app is designed to run in x64, you can get x64 odac and your code can be AnyCPU. Make sure in project properties you don't select "prefer 32 bit". If you run 32 bit - install x32 ODAC as well and set "prefer 32 bit". ODP.net - just go to the page in previous comment, it shows ho to get. Get whatever the latest version. – T.S. Feb 27 '21 at 01:16
  • ODAC will install the driver. ODP package will be your app's interface to that driver – T.S. Feb 27 '21 at 01:18
  • @T.S. love you love you, pal!. It just worked!!. You're so amazing!. Thank you very very much :D – JustToKnow Feb 27 '21 at 16:10

0 Answers0