title: Could not load file or assembly 'System.Data error when deploying application on production database
body: <p><strong>The problem:</strong>
  When deploying my applications to the production database i get the following error:</p>
  
  <pre><code>Could not load file or assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
  
     at ConsoleApplication2.Database.DBConnect.Initialize(String username, String password, String IP)
     at ConsoleApplication2.Database.DBConnect..ctor(String username, String password, String IP) in C:\Users\Vincent\Documents\Visual Studio 2008\Projects\ConsoleApplication2\ConsoleApplication2\DBConnect.cs:line 26
     at ConsoleApplication2.Database..ctor() in C:\Users\Vincent\Documents\Visual Studio 2008\Projects\ConsoleApplication2\ConsoleApplication2\Database.cs:line 20
     at ConsoleApplication2.Main..ctor() in C:\Users\Vincent\Documents\Visual Studio 2008\Projects\ConsoleApplication2\ConsoleApplication2\Main.cs:line 16
  </code></pre>
  
  <p><strong>What i know:</strong> it isn't actually the System.Data.dll that has a problem. </p>
  
  <p>Since I've started making a clean console application. 
  First just using Console.write(). when that worked i made a new class and did some general computations (also without problems) than I decided to create a MySQL connection using the MySQL.data.MySqlClient; from the Mysql.data.dll this is when the error occured again. I got the dll from <a href="http://dev.mysql.com/downloads/connector/net/6.1.html" rel="nofollow noreferrer">the mysql site</a>.</p>
  
  <p><strong>the strange part:</strong>
  this dll has always worked on my computer (on which I created the applications) and on 2 different servers (1 of which I set up just for testing these applications to see if i would get the same problem)</p>
  
  <p><strong>some specs:</strong>
  my computer runs windows 7 32 bit.
  the production database runs windows 2003 service pack 2 as do the test server and the other server I've tried it on.</p>
  
  <p><strong>Some other stuff I've done:</strong>
  I have created an installer (.msi and .exe) both install .net 3.5 service pack 1 and .net 2.0 service pack 2.0 and .net 3.0 service pack 2.
  i found it strange that it would install all those .net frameworks but to install 3.5 you need 2.0 so that made sense (not sure about why it installed 3.0 though)</p>
  
  <p>I've also tried running the application without the MySQL connector installed (so just place the mysql.data.dll in the application folder) and I've tried with the MySQL connector installed (so no dll's in the application folder)</p>
  
  <p>I've tried copying my .net framework to the production database (this was before i knew it was about the mysql.data.dll and not the system.dll or system.data.dll)</p>
  
  <p>I've tried everything i could think of yet nothing works, it works fine on all other computers/databases just not on the 1 we want to deploy the application...</p>
  
  <p><strong>The code where the error occurs:</strong></p>
  
  <pre><code>        public DBConnect(string username, string password, string IP)
          {
              Console.WriteLine("dbconnect contsrutctor");
              Initialize(username, password, IP);
          }
  
          private void Initialize(string username, string password, string IP)
          {
              Console.WriteLine("initializing strings");
              string server = IP;
              string database = "";
              string connectionString;
              connectionString = "SERVER=" + server + ";" + "DATABASE=" +
              database + ";" + "UID=" + username + ";" + "PASSWORD=" + password + ";";
              Console.WriteLine("initializing mysqlconnection");
              //MySqlConnection connection = new MySqlConnection(connectionString);
          }
  </code></pre>
  
  <p>i have commented the line: </p>
  
  <pre><code>MySqlConnection connection = new MySqlConnection(connectionString);
  </code></pre>
  
  <p>and the applications runs without errors, when I un-comment it the error occurs again.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have noticed a strange thing: when ever it gets to the method (not the line) of where the <code>MySqlConnection</code> is created the error is thrown. If you would look at the above code sample the first <code>Console.WriteLine("initializing strings");</code> does not even show in my console. I find this quite strange since you would expect the error to be thrown on the <code>MySqlConnection connection = new MySqlConnection(connectionString);</code> line and not at the start of the method.</p>
  
  <p><strong>EDIT 2</strong>
  I thought i found an answer so i posted it:</p>
  
  <blockquote>
    <p>"Though i have checked the system.data.dll and system.dll versions and
    file paths (which were exactly the same on all 3 machines I did find
    the problem to be with these files.</p>
    
    <p>In my application I've set the "copy local" to true and after this it
    worked.</p>
    
    <p>I find this extremely odd since I've tried replacing the dll's on the
    production server with my own and this did not work. also just placing
    the dll's in the application folder did not help either. I had to
    specifically specify the application to copy the dll's it self.</p>
    
    <p>anyway it's working properly now although I'm not quite convinced i
    like this solution...</p>
    
    <p>I definitely do not like this because i need to do this to half of the
    dll's (yes half not all just about half of them).</p>
    
    <p>any better options are still welcome."</p>
  </blockquote>
  
  <p>however I failed to mention it worked on my test application, the real application can't find system.transactions this time. so it's still not the right solution though it did clear the error about the system.data.dll i still can't run the program because of a similar error for a different file.</p>
  
  <p>So since i'm still having the same error but on a different file (which i can't change the "copy local" setting to true since it's not referenced by me) i've deleted the answer and placed it here as an edit since the problem still isn't solved.</p>
  
  <p><strong>EDIT 3</strong>
  I've run Fuslogvw.exe and this is the result:</p>
  
  <blockquote>
    <p><strong>* Assembly Binder Log Entry  (12/5/2013 @ 8:43:13 AM) *</strong></p>
    
    <p>The operation failed. Bind result: hr = 0x80070002. The system cannot
    find the file specified.</p>
    
    <p>Assembly manager loaded from: 
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll Running
    under executable  C:\Program Files\Custommate\email sorteer
    service\EmailSorteerService.exe
    --- A detailed error log follows. </p>
    
    <p>=== Pre-bind state information === LOG: User = NAVMATE\Administrator LOG: DisplayName = System, Version=2.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089  (Fully-specified) LOG: Appbase =
    file:///C:/Program Files/Custommate/email sorteer service/ LOG:
    Initial PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base =
    NULL LOG: AppName = NULL Calling assembly : EmailSorteerService,
    Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
    === LOG: This bind starts in default load context. LOG: No application configuration file found. LOG: Using machine configuration file from
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
    LOG: Post-policy reference: System, Version=2.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089 LOG: GAC Lookup was unsuccessful. LOG:
    Attempting download of new URL 
    file:///C:/Program
    Files/Custommate/email sorteer service/System.DLL. LOG: Attempting
    download of new URL 
    file:///C:/Program Files/Custommate/email sorteer
    service/System/System.DLL. LOG: Attempting download of new URL
    file:///C:/Program Files/Custommate/email sorteer service/System.EXE.
    LOG: Attempting download of new URL 
    file:///C:/Program Files/Custommate/email sorteer service/System/System.EXE. LOG: All
    probing URLs attempted and failed.</p>
  </blockquote>
  
  <p>Meaning it's trying to load the dll's from the folder i'm running the application from, i find this strange since i don't know what is causing this. (I have made sure copy local is set to false so that couldn't be the problem)</p>
  
  <p>so the new question: how do i make sure it loads it from the right place?</p>