2011-10-10 63 views
3

当前正在运行单声道。我在位于/ usr/lib/mono/gac的gac文件夹中加载了MySQL并安装了connector/net。问题是,每次我尝试用一​​个简单的连接测试来运行它,我得到以下错误:C#MySql Connector/Net问题

** (/home/holland/Code/csharp/test/Test/bin/Debug/Test.exe:10278): WARNING **: The following assembly referenced from /home/holland/Code/csharp/test/Test/bin/Debug/Test.exe could not be loaded: 
    Assembly: MySql.Data (assemblyref_index=1) 
    Version: 6.4.4.0 
    Public Key: c5687fc88969c44d 
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/home/holland/Code/csharp/test/Test/bin/Debug/). 


** (/home/holland/Code/csharp/test/Test/bin/Debug/Test.exe:10278): WARNING **: Could not load file or assembly 'MySql.Data, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. 

** (/home/holland/Code/csharp/test/Test/bin/Debug/Test.exe:10278): WARNING **: Missing method .ctor in assembly /home/holland/Code/csharp/test/Test/bin/Debug/Test.exe, type MySql.Data.MySqlClient.MySqlConnection 

** (/home/holland/Code/csharp/test/Test/bin/Debug/Test.exe:10278): WARNING **: Could not load file or assembly 'MySql.Data, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. 

** (/home/holland/Code/csharp/test/Test/bin/Debug/Test.exe:10278): WARNING **: Missing method .ctor in assembly /home/holland/Code/csharp/test/Test/bin/Debug/Test.exe, type MySql.Data.MySqlClient.MySqlConnection 

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'MySql.Data, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. 
File name: 'MySql.Data, Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' 
    at Test.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0 

如果我没有记错

这里是我的代码应该是一个集文件:

using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.Data; 
using MySql.Data.MySqlClient; 

namespace Test 
{ 
    public class Database 
    { 
     public Database() 
     { 

     } 

     public static IDbConnection MainConnect() 
     { 
      string connectionInfo = 
      "Server=localhost;"+ 
      "Database=ecom_main;"+ 
      "User ID=root;"+ 
      "Password=xxxxxxx"+ 
      "Pooling=false;"; 

      return new MySqlConnection(connectionInfo); 
     } 
using System; 
using System.Data; 
using MySql.Data.MySqlClient; 

namespace Test 
{ 
    class MainClass 
    { 
     public static void Main (string[] args) 
     { 
      IDbConnection dbMain = Database.MainConnect(); 

      Console.WriteLine(dbMain); 
     } 
    } 
} 
+0

你是否检查过与MONO_PATH变量相同的文件夹? –

+0

MONO_PATH变量在哪里? – zeboidlund

+0

你是如何安装组件的?你使用gacutil吗? –

回答

4

我有同样的问题,我解决了它下面的这个步骤:

  1. 使该DLL的一个副本情况下sesitive:
#cp mysql.data.dll MySql.Data.dll
  1. 安装连接器
    #gacutil -i -package 2.0 MySql.Data.dll
    这将在GAC并在/ usr/lib中/单增加了一个符号链接/2.0
  2. 如果程序集没有出现在monodevelop中,那么你可以将项目中的dll的引用添加到/usr/lib/mono/2.0

+ info:http://dev.mysql.com/doc/refman/5.1/en/connector-net-installation-unix.html

+0

出现同样的问题。足以让它具有感性(运行Ubuntu)。谢谢。 – BlueVoodoo

+0

同样适用于我。将'mysql.data.dll'重命名为'MySql.Data.dll'使单声道运行没有任何问题。 – h2ooooooo

+0

让大小写敏感对我也有帮助,可笑的是:p – Traubenfuchs