C# MySql Connector/Net问题

3

目前正在运行的是Mono。我将MySQL加载并安装了connector/net,放置在位于/usr/lib/mono/gac的gac文件夹中。问题在于每次尝试使用简单连接测试运行时,我都会遇到以下错误:

** (/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);
        }
    }
}

你检查了一下是否是与MONO_PATH变量相同的文件夹吗? - Jesus Ramos
MONO_PATH变量在哪里? - zeboidlund
你是如何安装程序集的?你使用了gacutil吗? - Jon Skeet
MONO_PATH 是一个环境变量,正如 Jon 所说,你是否使用 gacutil 将其注册到 GAC 中,将其放在文件夹中并不总是有效。 - Jesus Ramos
更新:我在目录上执行了“export MONO_PATH”,但是很遗憾我没有得到任何东西。 - zeboidlund
显示剩余2条评论
1个回答

4

我曾遇到同样的问题,按照以下步骤解决:

  1. 复制dll文件并区分大小写:
#cp mysql.data.dll MySql.Data.dll
  1. 安装连接器
    #gacutil -i -package 2.0 MySql.Data.dll
    这将安装在GAC中,并在/usr/lib/mono/2.0中添加一个符号链接
  2. 如果程序集在monodevelop中未出现,则可以将dll文件的引用添加到项目的 /usr/lib/mono/2.0 中

+更多信息请访问: http://dev.mysql.com/doc/refman/5.1/en/connector-net-installation-unix.html


遇到了同样的问题。只需要将它区分大小写即可(运行Ubuntu)。谢谢。 - BlueVoodoo
对我来说也是一样。将 mysql.data.dll 重命名为 MySql.Data.dll 可以使 Mono 无任何问题地运行。 - h2ooooooo
将它区分大小写也对我有帮助,太荒谬了 :p - ASA

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接