2011-10-10 67 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