views:

410

answers:

4

I am using NHibernate against an Oracle database with the NHibernate.Driver.OracleDataClientDriver driver class. I have an integration test that pulls back expected data properly when executed through the IDE using TestDriven.net. However, when I run the unit test through the NUnit GUI or Console, NHibernate throws an exception saying it cannot find the Oracle.DataAccess assembly. Obviously, this prevents me from running my integration tests as part of my CI process.

NHibernate.HibernateException : The IDbCommand and IDbConnection implementation in the assembly Oracle.DataAccess could not be found. Ensure that the assembly Oracle.DataAccess is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use element in the application configuration file to specify the full name of the assembly.*

I have tried making the assembly available in two ways, by copying it into the bin\debug folder and by adding the element in the config file. Again, both methods work when executing through TestDriven in the IDE. Neither work when executing through NUnit GUI/Console.

The NUnit Gui log displays the following message.

21:42:26,377 ERROR [TestRunnerThread] ReflectHelper [(null)]- Could not load type Oracle.DataAccess.Client.OracleConnection, Oracle.DataAccess. System.BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess, Version=2.111.7.20, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format.

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

File name: 'Oracle.DataAccess'

I am running NUnit 2.4.8, TestDriven.net 2.24 and VS2008sp1 on Windows 7 64bit. Oracle Data Provider v2.111.7.20, NHibernate v2.1.0.4.

Has anyone run into this issue, better yet, fixed it?

A: 

I had a similar problem when configuring NHibernate. The thing is that most of test runners are using app.config that is placed with your tests dll. But some versions of NUnit don't. Thats why your system stays in not configured state for the tests. You can try to configure NHibernate mannually from the test. Hope it helps

Sly
A: 

Sly, Thanks for the reply. However, the NUnit test runner was using the correct configuration file as I was testing by pulling a known value out of the expected configuration file.

I am assuming this has something to do with my configuration, specifically with either Windows 7 in general or the 64bit version. I went ahead and installed/configured the Oracle client on the build server (W2k3 Server). I moved the test onto the build server and ran the same scenarios described above and the tests worked as expected in all cases.

I followed this up by running through the scenarios on two of the other developer workstations (Win XP 32bit with same toolset versions) and the tests worked as expected in all cases.

I'm perplexed but satisfied for now. I can run my integration tests through the IDE and can execute them on the build server through our CI automation. Only problem now is I can't test the automation build project on my development workstation.

Cliff
A: 

I was getting this error when I tried to run an application which used Oracle.DataAccess.dll (odp.net version 2.111.7.20). I was shipping the orcale 11g instant client alongside the application. On 64 bit servers it would fail. However, the client assemblies I was shipping were 32 bit so I compiled a version of the app with the cpu flag set 32bit and now it works fine. This is because the server runs the entire component within the wow64 emulator when you tell it the app is 32bit expicitly.

Tomo
Thanks, Tomo. This sounds interesting. I have heard of a number of "strange" behaviors that are fixed by explicitly setting the 32bit compiler option. I'll try this in the next couple of days and post another comment if it works.
Cliff
A: 

I may have just solved a similar/same problem on my local machine by going into the build settings for the test project and changing platform target from "any cpu" to "x86"

charley