The problem: When deploying my applications to the production database i get the following error:
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
What i know: it isn't actually the System.Data.dll that has a problem.
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 the mysql site.
the strange part: 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)
some specs: 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.
Some other stuff I've done: 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)
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)
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)
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...
The code where the error occurs:
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);
}
i have commented the line:
MySqlConnection connection = new MySqlConnection(connectionString);
and the applications runs without errors, when I un-comment it the error occurs again.
EDIT
I have noticed a strange thing: when ever it gets to the method (not the line) of where the MySqlConnection
is created the error is thrown. If you would look at the above code sample the first Console.WriteLine("initializing strings");
does not even show in my console. I find this quite strange since you would expect the error to be thrown on the MySqlConnection connection = new MySqlConnection(connectionString);
line and not at the start of the method.
EDIT 2 I thought i found an answer so i posted it:
"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.
In my application I've set the "copy local" to true and after this it worked.
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.
anyway it's working properly now although I'm not quite convinced i like this solution...
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).
any better options are still welcome."
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.
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.
EDIT 3 I've run Fuslogvw.exe and this is the result:
* Assembly Binder Log Entry (12/5/2013 @ 8:43:13 AM) *
The operation failed. Bind result: hr = 0x80070002. The system cannot find the file specified.
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.
=== 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.
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)
so the new question: how do i make sure it loads it from the right place?