0

I have an application that hits an oracle database using Oracle.DataAccess and runs just fine.

The problem comes when I reference the same dll in my test project and run the tests.

Integration tests that hit the db fail to run with the following exception:

"Message: System.BadImageFormatException : Could not load file or assembly 'Oracle.DataAccess, Version=2.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format."

Is it possible that there's an issue with the NUnit runner?

If so, i'm lost regarding what steps to take so that it runs correctly.

Thanks in advance

Rick
  • 345
  • 2
  • 13
  • Have a look at this: https://stackoverflow.com/questions/659341/the-provider-is-not-compatible-with-the-version-of-oracle-client#25412992 – Wernfried Domscheit Nov 13 '19 at 14:15
  • Thanks @WernfriedDomscheit, unfortunately that is not the error I'm getting and the weird part is that i'm referencing the same dll from both projects. The application works fine, the test project fails miserably. – Rick Nov 13 '19 at 14:34
  • The exact error message have been changed over time. Verify all listed items carefully. – Wernfried Domscheit Nov 13 '19 at 14:37
  • I did, if I try to load the assembly explicitly (using reflection), I get the same issue – Rick Nov 13 '19 at 15:34
  • Check with [Assembly.Location](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.location?view=netframework-4.8) which DLL is actually loaded. There might be some redirect, see https://stackoverflow.com/questions/44818069/how-to-load-specific-version-of-assembly-from-gac – Wernfried Domscheit Nov 13 '19 at 19:07
  • @WernfriedDomscheit found the answer to my problem – Rick Nov 14 '19 at 22:42

2 Answers2

0

Every time I encountered that error it was because the entry point DLL was not set up to build for 32/64 bit. If you're using a 32bit Oracle.DataAccess DLL, make sure your test project is also set up to run in 32bit mode.

(Also make sure that the machine you run the tests on, has the correct Oracle client installed: 32 or 64 bit).

Debug Configuration

Don't forget to configure the platform correctly for all your solution configurations (Debug, Release, ...):

Release Configuration

ultddave
  • 188
  • 1
  • 11
0

For posterity:

Tests can run in either x86 or x64.

That can be switched here:

Changing test processor architecture

If your app uses x86 oracle, then leave the tests in x86. If your app uses x64 oracle, then switch the tests processor architecture to x64.

What led me to the answer was the fact that the application worked just fine, but when running the tests they failed to run. Hence asking the question "wait, in what context does the test code run" helped me find this.

Thanks to the previous comments and answers for your support. This is the reply I was looking for.

Rick
  • 345
  • 2
  • 13