12

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?

10
  • Just to be sure - what version is your system.data dll?
    – S_F
    Nov 26, 2013 at 8:13
  • I've just searched on the production database it has 4 system.data (2 of which with small letters and 3 of which with capital D. it contains some different versions 2.0. 4.0 1.1 my own computer has the same though
    – Vincent
    Nov 26, 2013 at 8:19
  • I meant the one that is referenced in your console application.
    – S_F
    Nov 26, 2013 at 8:22
  • the one referenced in my project: v2.0.50727 this version is also on the production database. In the exact same folder as on my computer
    – Vincent
    Nov 26, 2013 at 8:24
  • Verify your process user has permission to access the necessary files on your production environment.
    – Chris
    Nov 26, 2013 at 9:04

5 Answers 5

7
+50

The reason why the exception is thrown as soon as you enter the method is simple - the JIT compiler only needs to resolve the references then. MySqlConnection requires System.Data, and it's the first method to do so, so that's when the exception is thrown.

As for debugging the issue, it does seem like improperly installed .NET framework on the target machine. You should try How to enable assembly bind failure logging (Fusion) in .NET to have a look at where .NET is actually trying to find the library, and why it discards any that it finds at all.

If it doesn't lead you to solve your problem, I'd try uninstalling and reinstalling .NET framework 2.0, and then 3.5.

The reason Copy Local sort of works is because then the application doesn't try to load the DLL from the Global Assembly Cache, but rather from the executable directory of your application. However, your real problem is that it isn't finding the right DLL in GAC.

If Fusion shows you that the MySQL library tries to load a wrong version of System.Data, you can use an application manifest to force it to load a different version (which should hopefully be compatible). You can read about application manifests here - http://msdn.microsoft.com/en-us/library/aa374191(VS.85).aspx

Good luck.

15
  • i'm sorry to respond so late, but until now there was no time to do work on the server (since it's been quite busy) however, I cannot find the fusion program, the server does not contain a folder: microsoft SDK
    – Vincent
    Dec 5, 2013 at 7:35
  • You have to install VS or Windows SDK on the server. Or, you can download the log and view it on your computer. Also, if you enable the logging, it should show up in the ASP.NET error page, at least a part of it.
    – Luaan
    Dec 5, 2013 at 7:43
  • I've just moved the file FUSLOGVW.exe from my pc to the server and it worked fine :P i now have a logg, i think it's indicating it's trying to load it from the folder the application is in. i'll post the logg in my question.
    – Vincent
    Dec 5, 2013 at 7:45
  • @VincentAdvocaat: I've had a look at the log, and it in fact does try to load the (correct) System.DLL from GAC - but it's not there. That's... very weird. Now, you could of course install the proper DLLs into GAC manually (using gacutil /if WhateverDll.dll for each of the failing DLLs), but you apparently don't have the code .NET DLLs in GAC, which shouldn't be. I'd try uninstalling all of the .NETs, trying to install them again (pay close attention to any logs during the installation), and give it another try. It might be that .NET installation partially failed due to low permissions or...
    – Luaan
    Dec 5, 2013 at 8:37
  • @VincentAdvoccat : I've also found that sometimes having .NET 1.1 installed can screw things up - be sure to uninstall that one as well, if it's there.
    – Luaan
    Dec 5, 2013 at 8:39
2

Whenever I have seen issues like this, it is because I have not deployed the correct version of the library in question or because I am actually missing a library. I think others already referenced this but I wanted to repeat to emphasize that this is the main issue.

In order to solve these sorts of issues you can do two things. First, understand the order in which libraries are loaded:

  • Look in the Global Assembly Cache (GAC)
  • Search the folder your program is running from
  • Search the current directory
  • Search the system folder (System32 or SysWow64)
  • Search any other folders in the environment %PATH% variable

Once you understand that, you can look in each of these locations for wrong or conflicting versions of the library that you are referencing. Since System.Data is a library that comes with .NET I would guess that your build computer has a different version of .NET installed than you have on your computer you are trying to deploy to.

The other thing that I have found to be really helpful is a tool called fuslogvw.exe (http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.110).aspx). If you follow the instructions on the FusionLog site you can trace .NET as it tries to load various assemblies. Simply enable the tool then check the logs file after you get the error. This should indicate where .NET was looking for the file and possibly why it failed.

As others said - best of luck!

1
  • luaan recommended the same program, i've run it and it shows it's trying to load the system.dll from the folder the application is in, which is strange, because i don't know why it's doing that
    – Vincent
    Dec 5, 2013 at 7:55
1

To find a which .dll it is ultimately failing to find ("or one of its dependencies" in the error message) and from where it is attempting to load it you can try Process Monitor from the SysInternals suite.

It's a simple download, unzip, and run in place. I suggest you then add a filter for your app's name (or whatever else you can use to uniquely identify it) and then just watch for it to try to load a .dll and fail. You can apply more filters to narrow down the list of events such as Operation is QueryNameInformationFile (first event it tries when locating a file). Note that for a lot of .dlls it will try a few places before ultimately finding a copy, so you're looking for a series of events referencing the same file name with no Success result at the end.

Best of luck.

1

I had this error when Windows update was installing .Net 4.5.2 at the same time I was debugging my code in 4.5.1.

0
0

I had the same problem,

First, you must copy your reference dll file into the bin folder of the main project that uses it and include the file at the references section of the main project inside VS.

Second, if you are using your main project as a library project and including it inside another project (a second project) then add the same reference dll file into the bin folder of this second project and also include this copied file at the references section of the second project at VS.

This workaround solved my problem, I hope it helps you too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.