title: Referencing the correct version of Oracle.DataAccess in .NET
body: <p>I'm trying to reference Oracle.DataAccess from a .NET 4.0 project, written on Visual Studio 2013. My machine's GAC has two versions of Oracle.DataAccess installed: 4.112.1.2 (provided by Oracle version 11gr2) and 4.121.2.0 (provided by Oracle version 12c). </p>
  
  <p>I want to reference version 4.112.1.2 (my project must run with %ORACLE_HOME% set to 11gr2's install location, and referencing 4.121.2.0 causes runtime failures when this is the case). I do not have an admin account on my machine, so I can't just uninstall the 12c dll.</p>
  
  <p>I have tried the following steps to force the executable to load the 4.112.1.2 dll at runtime:</p>
  
  <ol>
  <li><p>Reference the dll in my .csproj file using the strong name:</p>
  
  <p><code>&lt;Reference Include="Oracle.DataAccess, Version=4.112.1.2, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86"/&gt;</code></p></li>
  <li><p>Updating my App.Config file to force a redirect:</p></li>
  </ol>
  
  <p></p>
  
  <pre><code>&lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/&gt;
      &lt;codeBase version="4.112.1.2" href="C:\Path\To\11gr2\Oracle.DataAccess.dll"/&gt;
      &lt;bindingRedirect oldVersion="4.121.2.0" newVersion="4.112.1.2"/&gt;
      &lt;publisherPolicy apply="no"/&gt;
  &lt;/dependentAssembly&gt;
  </code></pre>
  
  <p></p>
  
  <ol start="3">
  <li><p>I modified my PATH to make the 11gr2 Client's bin directory first on my path:</p>
  
  <p><code>set PATH="C:\path\to\11gr2\BIN;%PATH%"</code></p></li>
  </ol>
  
  <p>No matter what I do, however, the executable loads the 4.121.2.0 dll from the GAC at runtime. Here's what it says when I attach a debugger:</p>
  
  <pre><code>'MyApp.exe' (Managed (4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\Oracle.DataAccess\v4.0_4.121.2.0_89b483f429c47342\Oracle.DataAccess.dll'
  </code></pre>
  
  <p>I've read through Microsoft's documentation on assembly binding (<a href="https://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.110).aspx" rel="nofollow noreferrer">here</a> and <a href="https://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx" rel="nofollow noreferrer">here</a>). I've also read the StackOverflow answers that seem to be related to my issue (<a href="https://stackoverflow.com/questions/25131753/use-a-specific-version-of-a-dll-in-c-sharp">here</a> and <a href="https://stackoverflow.com/questions/8324915/strong-name-for-a-dll-in-net">here</a>), but nothing has worked.</p>
  
  <p>How do I force .NET to load the correct DLL version at runtime from the GAC?</p>
  
  <p>EDIT:</p>
  
  <p>Wernfried's answer leads me to think I may be looking at this the wrong way. Here's exactly what's happening:</p>
  
  <p>I run my application with ORACLE_HOME=C:\ORACLE\ora12c, everything works as normal (database accesses succeed, application is happy)</p>
  
  <p>I run my application with ORACLE_HOME=C:\ORACLE\ora11gr2 (the required version). Application crashes with following exception:</p>
  
  <pre><code>Oracle.DataAccess.Client.OracleException ORA-12557: TNS:protocol adapter not loadable.
  &lt;stacktrace follows&gt;
  </code></pre>
  
  <p>Following the stacktrace, I discovered that the error occurred in the call my application made to create a database connection. I've checked my connection string and verified that it is correct (and that it is the same connection string that was succeeding with 12c). I then discovered that version of the Oracle.DataAccess dll I was calling was the 12c one, not the 11gr2 one. From this, I concluded that I needed to modify the call to load the dll to "force" the 11gr2 one. If I'm barking up the wrong tree, please let me know!</p>