title: How to use native dll's in ASP.NET?
body: <p>Question:</p>
  
  <p>I use System.Data.OracleClient.</p>
  
  <p>System.Data.OracleClient requires OracleInstantClient, which are native dll's.
  So in order to use System.Data.OracleClient, I need the native dll's installed, or in a folder in the path environment variable.</p>
  
  <p>Now, the base problem is, I don't have administrator rights (company laptop - corporate stupidity - not going to change)...<br />
  So I can neither install anything, nor copy anything in a folder in PATH, nor can I add a folder to the path environment variable, nor can I restart/administer IIS or any other service...</p>
  
  <p>So as a test, I just copied oci.dll and oraociei11.dll into the same folder as the WinForms .exe.<br />
  This worked fine. I was able to access the Oracle database (SELECT * FROM COUNTRIES) without problems.</p>
  
  <p>But now, I need to perform the same query in an ASP.NET solution.
  The problem is, ASP.NET dll's get shadow copied to a temporary folder when they execute.</p>
  
  <p>Now to get the dll's to the webapp bin non-the-less, <br />
  in Global.asax in </p>
  
  <pre><code>public class MvcApplication : System.Web.HttpApplication
  </code></pre>
  
  <p>I overwrote Init with this:</p>
  
  <pre><code>public override void Init()
  {
      int iBitNess = IntPtr.Size;
      //System.Windows.Forms.MessageBox.Show(iBitNess.ToString());
      // iBitNess = 4, so 32 bit dll's are right
  
  
  
      string strTargetDirectory = System.Reflection.Assembly.GetExecutingAssembly().Location;
      strTargetDirectory = typeof(DB.Abstraction.cDAL).Assembly.Location;
      strTargetDirectory = typeof(MvcApplication).Assembly.Location;
      strTargetDirectory = System.IO.Path.GetDirectoryName(strTargetDirectory);
  
      string strSourcePath = Server.MapPath("~/bin/dependencies/InstantClient");
      string[] astrAllFiles = System.IO.Directory.GetFiles(strSourcePath, "*.dll");
  
      foreach (string strSourceFile in astrAllFiles)
      {
          string strTargetFile = System.IO.Path.GetFileName(strSourceFile);
          strTargetFile = System.IO.Path.Combine(strTargetDirectory, strTargetFile);
          System.IO.File.Copy(strSourceFile, strTargetFile);
      }
  
      base.Init();
  } // End Sub Init
  </code></pre>
  
  <p>in order to copy the native dll's to the supposedly correct location.
  But I still get DllNotFound Exception...</p>
  
  <p>Where or how do I have to put a native dll in a ASP.NET application ?</p>
  
  <p><strong>I say again: I cannot set environment variables, and I cannot copy the dlls to a folder that is in path.</strong> (which would normally solve the problem).</p>
  
  <p>As you see with the multiple occurences of</p>
  
  <pre><code>strTargetDirectory =
  </code></pre>
  
  <p>I tried several possibilites, none of which worked.</p>