在生产数据库上部署应用程序时无法加载文件或程序集“System.Data”错误 [英] Could not load file or assembly 'System.Data error when deploying application on production database

查看:133
本文介绍了在生产数据库上部署应用程序时无法加载文件或程序集“System.Data”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:
将应用程序部署到生产数据库时,会收到以下错误:

 code>无法加载文件或程序集System.Data,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089或其依赖关系之一。该系统找不到指定的文件。 

在ConsoleApplication2.Database.DBConnect.Initialize(String username,String password,String IP)
在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:第20行
在ConsoleApplication2.Main..ctor()在C:\Users\\ \\Vincent\Documents\Visual Studio 2008\Projects\ConsoleApplication2\ConsoleApplication2\Main.cs:第16行

我知道:它实际上没有System.Data.dll有问题。



由于我已经开始制作一个干净的控制台应用程序。
首先只是使用Console.write()。当我做了一个新的类,做了一些一般的计算(也没有问题)比我决定使用MySQL.data.MySqlClient创建一个MySQL连接;从Mysql.data.dll这是当错误再次发生时。我从 mysql网站获得了dll。



奇怪的部分:
这个dll一直在我的电脑(我在其上创建了应用程序)和2个不同的服务器(其中1个我设置只是为了测试这些应用程序,看看我是否会遇到同样的问题)



某些规格:
我的电脑运行Windows 7 32位。
生产数据库运行Windows 2003 Service Pack 2,测试服务器和我尝试过的其他服务器。



其他一些东西我已经完成了:
我已经创建了一个安装程序(.msi和.exe)都安装.net 3.5 service pack 1和.net 2.0 service pack 2.0和.net 3.0 service pack 2.
i发现很奇怪,它会安装所有这些.net框架,但要安装3.5,你需要2.0,这是有道理的(不知道为什么它安装3.0虽然)



我也尝试运行应用程序没有安装MySQL连接器(所以只需将mysql.data.dll放在应用程序文件夹中),我已经尝试使用MySQL连接器安装(所以在应用程序文件夹中没有dll)



我已经尝试将.net框架复制到生产数据库(这之前我知道这是关于mysql.data.dll,而不是system.dll或system.data .dll)



我已经尝试过我能想到的一切t没有任何作用,它在所有其他计算机/数据库上正常工作,不在1我们要部署应用程序...



错误的代码发生:

  public DBConnect(string username,string password,string IP)
{
Console.WriteLine(dbconnect contsrutctor);
初始化(用户名,密码,IP);
}

private void初始化(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 =+密码+;;
Console.WriteLine(initializing mysqlconnection);
// MySqlConnection connection = new MySqlConnection(connectionString);
}

我已经评论了这一行:

  MySqlConnection connection = new MySqlConnection(connectionString); 

并且应用程序运行没有错误,当我取消评论时,错误再次出现。 >

编辑



我注意到一个奇怪的事情:不是行)在$ code> MySqlConnection 被创建错误被抛出。如果你看看上面的代码示例,第一个 Console.WriteLine(initializing strings); 甚至不会显示在我的控制台中。我发现这很奇怪,因为你会期望错误被抛出在 MySqlConnection connection = new MySqlConnection(connectionString); 行,而不是在方法的开始。 p>

编辑2
我以为我找到一个答案,所以我发贴:



<虽然我已经检查了system.data.dll和system.dll版本和
文件路径(在所有3台机器上完全相同),但我发现
问题是这些文件。



在我的应用程序中,我将copy local设置为true,之后它
工作。



我发现这是非常奇怪的,因为我已经尝试用我自己的
生产服务器替换dll,这没有工作,也只是把
的dll在应用程序文件夹没有帮助,我不得不
具体指定应用程序复制dll的自己。



无论如何它的工作prope现在虽然我不太相信我
喜欢这个解决方案...



我绝对不喜欢这个,因为我需要做到这一半
dll(是的,一半不只是他们的一半左右)。



任何更好的选择仍然欢迎。


但是我没有提到它在我的测试应用程序上工作,真正的应用程序这次找不到system.transactions。所以它仍然不是正确的解决方案,虽然它清除了关于system.data.dll的错误我仍然无法运行该程序,因为一个类似的错误为不同的文件。



所以,因为我仍然有同样的错误,但在另一个文件(我不能将复制本地设置为true,因为它没有被引用)我删除了答案并将其放在这里作为编辑,因为问题仍然没有解决。



编辑3
我已经运行Fuslogvw.exe,这是结果:


*装配夹日志条目(12/5/2013 @ 8:43:13 AM)*



操作失败。绑定结果:hr = 0x80070002。系统不能
找到指定的文件。



装配经理从:
C:\WINDOWS\Microsoft.NET\Framework\\ \\v2.0.50727\mscorwks.dll在可执行文件C下运行
:\Program Files\Custommate\email sorteer
service\EmailSorteerService.exe
---详细的错误日志如下。



===预绑定状态信息=== LOG:User = NAVMATE\Administrator LOG:DisplayName = System,Version = 2.0.0.0,Culture = neutral,
PublicKeyToken = b77a5c561934e089(完全指定)日志:Appbase =
文件:/// C:/ Program Files / Custommate /电子邮件sorteer服务/日志:
初始PrivatePath = NULL日志:动态Base = NULL LOG:Cache Base =
NULL LOG:AppName = NULL调用程序集:EmailSorteerService,
Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null。
=== LOG:此绑定在默认加载上下文中启动。日志:未找到应用程序配置文件。日志:从
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未成功。日志:
尝试下载新的URL
文件:/// C:/ Program
文件/ Custommate /电子邮件sorteer服务/ System.DLL。日志:尝试
下载新的URL
文件:/// C:/ Program Files / Custommate / email sorteer
service / System / System.DLL。日志:尝试下载新的URL
文件:/// C:/ Program Files / Custommate / email sorteer service / System.EXE。
日志:尝试下载新的URL
文件:/// C:/ Program Files / Custommate / email sorteer service / System / System.EXE。日志:所有
尝试尝试和失败的探测URL。


意思是尝试从我正在运行的文件夹加载dll应用程序,我发现这个奇怪,因为我不知道是什么导致这个。 (我已经确保本地的副本设置为false,所以这不可能是问题)



所以新的问题:我如何确保它从正确的地方?

解决方案

只要您输入该方法,异常抛出的原因很简单 - JIT编译器只需要然后解析引用。 MySqlConnection需要System.Data,这是第一个这样做的方法,所以这是抛出异常。



关于调试问题,看起来好像是安装不正确.NET框架在目标机器上。您应该尝试如何启用程序集绑定失败日志记录(Fusion )在.NET中查看.NET实际上试图找到库的原因,以及为什么它抛弃任何找到的库。



如果没有引导你解决你的问题,我会尝试卸载并重新安装.NET Framework 2.0,然后是3.5。



是因为应用程序不会尝试从全局程序集缓存中加载DLL,而是从应用程序的可执行文件目录中。但是,您真正的问题是在GAC中找不到正确的DLL。



如果Fusion显示MySQL库尝试加载错误的System版本。数据,您可以使用应用程序清单强制其加载不同的版本(应该希望是兼容的)。您可以在这里阅读有关应用程序清单 - http:// msdn .microsoft.com / en-us / library / aa374191(VS.85).aspx



祝你好运。


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?

解决方案

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.

这篇关于在生产数据库上部署应用程序时无法加载文件或程序集“System.Data”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆