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

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

问题描述

问题:
当部署我的应用程序到生产数据库,我收到以下错误:

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

我知道什么:它实际上不是,有一个问题System.Data.dll中。

What i know: it isn't actually the System.Data.dll that has a problem.

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

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.

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

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)

一些规格:
我的计算机运行Windows 7 32位的。
的生产数据库运行的Windows 2003 Service Pack 2的作为做了测试服务器,我已经试过了对其他服务器。

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.

一些其他的东西我所做的:
我已经创建了一个安装程序(.msi和.exe)都安装.NET 3.5 Service Pack 1和.NET 2.0的Service Pack 2.0和.NET 3.0的Service Pack 2,$ b $双向觉得很奇怪,它会安装所有的.NET框架,但要安装3.5需要2.0这样有意义(不知道为什么它安装了3.0虽然)

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)

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

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)

我试图复制我的.NET Framework生产数据库(这是之前,我知道这是对mysql.data.dll,而不是对System.Dll或System.Data这.DLL)

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)

我用尽了一切我能想到的还没有什么作品,它适用于所有其他计算机精细/数据库只是没有在1,我们要部署应用...

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...

发生错误的代码:

        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.

修改

我注意到一个奇怪的事情:当过它获取方法(其中的MySqlConnection 创建错误的也不行)被抛出。如果你想看看上面的代码示例第一个 Console.WriteLine(初始化字符串); 甚至不显示在我的控制台。我觉得这很奇怪,因为你会希望在的MySqlConnection连接=新的MySqlConnection(的connectionString)上抛出的错误。行,而不是在方法开始

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.

编辑2
我想我找到了答案,所以我贴吧:

EDIT 2 I thought i found an answer so i posted it:

虽然我已经检查了system.data.dll中和System.dll中的版本和
文件路径(这是对所有3台一模一样的我确实发现
的问题与这些文件。

"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.

在我的应用程序已经设置了复制本地设置为true并在此之后它
工作。

In my application I've set the "copy local" to true and after this it worked.

我觉得这是非常奇怪,因为我试图用我自己更换
生产服务器上的dll的,这没有奏效。也只是把
DLL的在应用程序文件夹没有帮助的。我不得不
专门指定应用程序复制DLL的它的自我。

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...

我绝对不喜欢这个,因为我需要做到这一点的
的一半dll的(是一半不是所有的只是其中的一半)。

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."

不过,我没有提到它的工作在我的测试应用,实际应用无法找到System.Transactions的这个时候。所以它仍然不是正确的解决方案,虽然它没有明确了system.data.dll中我仍然无法运行,因为对于不同的文件类似错误的程序错误。

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.

所以,因为我仍然有同样的错误,但在不同的文件(我不能改变的复制本地设置为true,因为它不是由我引用的)我已经删除了答案,放在这里作为编辑,因为问题仍然没有得到解决。

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.

修改3
我已经运行Fuslogvw.exe,这是结果:

EDIT 3 I've run Fuslogvw.exe and this is the result:

*大会粘结剂日志条目(2013年12月5日@上午08时43分13秒)*

操作失败。绑定结果:HR = 0x80070002。该系统无法
找到指定的文件

The operation failed. Bind result: hr = 0x80070002. The system cannot find the file specified.

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

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.

===预绑定状态信息===日志:用户= NAVMATE\Administrator日志:显示名称=系统,版本= 2.0.0.0,文化=中立,
公钥= b77a5c561934e089(完全指定的)日志:应用平台=
档:/// C:/ Program Files文件/ Custommate /电子邮件sorteer服务/ LOG:
初始PrivatePath = NULL LOG:动态基地= NULL日志:缓存基=
NULL LOG:AppName的= NULL调用汇编:EmailSorteerService,
版= 1.0.0.0,文化=中立,公钥=空。
===日志:此绑定的默认加载上下文开始。日志:未找到应用程序配置文件。日志:从
C使用计算机配置文件:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config。
日志:后政策参考:系统,版本= 2.0.0.0,文化=中立,
公钥= b77a5c561934e089日志:GAC查找不成功。日志:
尝试新的URL
文件下载:/// C:/程序
文件/ Custommate /电子邮件sorteer服务/ system.dll中。日志:尝试新的URL
档的
下载:/// C:/ Program Files文件/ Custommate /电子邮件sorteer
服务/系统/ system.dll中。日志:尝试新的URL
文件下载:/// C:/ Program Files文件/ Custommate /电子邮件sorteer服务/ System.EXE。
日志:尝试新的URL
文件下载:/// C:/ Program Files文件/ Custommate /电子邮件sorteer服务/系统/ System.EXE。 LOG:所有
探测网址企图失败

=== 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.

这意味着它试图从我运行的文件夹加载DLL的从应用程序中,我发现这种奇怪的,因为我不知道是什么原因造成这一点。 (我已经确定复制本地设置为false,所以不可能是问题)

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?

推荐答案

为什么例外,只要你输入的方法很简单引发的原因 - JIT编译器只需要以解决引用即可。的MySqlConnection需要System.Data和它的第一种方法这样做的,所以当异常被抛出这就是。

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.

至于调试的问题,它似乎是安装不当在目标机器上的.NET框架。你应该尝试如何启用程序集绑定失败日志(融合)在.NET 来看看.NET的地方实际上是试图找到图书馆,以及为什么它丢弃任何它找到的。

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.

如果它不会导致你解决你的问题,我想尝试卸载并重新安装.NET框架2.0,然后3.5。

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

原因复制本地类作品是因为那么应用程序不会尝试加载从全局程序集缓存的DLL,而是从应用程序的可执行文件的目录。但是,你真正的问题是,它没有找到在GAC正确的DLL。

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.

如果融合显示你的MySQL库尝试加载系统的版本错误。数据显示,您可以使用一个应用程序清单,以迫使它加载不同的版本(应该很有希望兼容)。你可以阅读有关的应用体现在这里 - http://msdn.microsoft.com/en -us /库/ aa374191(VS.85)的.aspx

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

祝你好运。

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

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