5
votes

I'm trying to run some unit tests that perform execute some SQL commands directly to an Oracle database and I get the following exception when the unit tests are started:

Testmethod1 threw exception:
System.IO.FileNotFoundException: 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.

I have Oracle.DataAccess in the project references (added through NuGet) and I have I have the Oracle Data Provider installed.

I even have some other projects using Oracle.DataAccess that run in this machine without problems. It seems that only Microsoft.Net Unit Test Framework (MSTest) is not able to load the assembly.

This is the log taken from Fusion Log Viewer:

*** Assembly Binder Log Entry  (23/08/2013 @ 04:50:07 p.m.) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\QTAgent32_40.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = ...
LOG: DisplayName = Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342
 (Fully-specified)
LOG: Appbase = file:///...C:/<solution_folder>.../TestResults/.../Out
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = QTAgent32_40.exe
Calling assembly : ...<project_name>..., Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\...<solution_folder>...\TestResults\...\Out\...<project_name>....DLL.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/...<solution_folder>.../TestResults/.../Out/Oracle.DataAccess.DLL.
LOG: Attempting download of new URL file:///C:/...<solution_folder>.../TestResults/.../Out/Oracle.DataAccess/Oracle.DataAccess.DLL.
LOG: Attempting download of new URL file:///C:/...<solution_folder>.../TestResults/.../Out/Oracle.DataAccess.EXE.
LOG: Attempting download of new URL file:///C:/...<solution_folder>.../TestResults/.../Out/Oracle.DataAccess/Oracle.DataAccess.EXE.
LOG: All probing URLs attempted and failed.

It states the assembly was not found in the GAC, but I did found it: C:\Windows\Microsoft.NET\assembly\GAC_64\Oracle.DataAccess\v4.0_4.112.3.0__89b483f429c47342\Oracle.DataAccess.dll\

It's also worth noting is that the above log shows QTAgent32_40.exe even though I have selected in Visual Studio menu TEST -> Test Settings -> Default Processor Architecture -> X64. Before doing so I was getting a BadImageFormatException instead.

Additional notes:

  • The Oracle Data Provider that I have installed is the 64 bit version.
  • The reference already has Copy Local=True
1
Turn on fusion logging to see if that helps you figure out what file is missing: hanselman.com/blog/…John Koerner
Didn't know about it. Thanks. I just added it to the questionmmutilva
Are your tests running as a 32 bit process?John Koerner
Nope, 64 bit and the Oracle Data Provider installed and referenced from the project is the 64 version... Otherwise I would get a BadImageFormatException instead (been there)mmutilva
A quick fix would be to set CopyLocal to true on the reference, but it should work from the GAC.John Koerner

1 Answers

6
votes

Found the problem.

There was a .testsettings file forcing the tests to be run in 32 bit mode regardless of me selecting TEST -> Test Settings -> Default Processor Architecture -> X64.

The weird thing is that if I select X86 I get the proper BadImageFormatException at runtime, while if the architecture is forced in the .testsettings file I get FileNotFoundException, which is a little misleading.