Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.IO.FileNotFoundException: Could not load file or assembly 'Oracle.DataAccess, ... when running unit tests

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
like image 903
mmutilva Avatar asked Aug 23 '13 19:08

mmutilva


People also ask

Can not load file or assembly or one of its dependencies?

In summary if you get the "Could not load file or assembly error", this means that either your projects or their references were built with a reference to a specific version of an assembly which is missing from your bin directory or GAC.


1 Answers

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.

like image 90
mmutilva Avatar answered Sep 30 '22 05:09

mmutilva