【问题标题】:C# MySql Connector/Net issuesC# MySql 连接器/网络问题
【发布时间】:2011-12-04 06:06:38
【问题描述】:

当前正在运行 Mono。我在位于/usr/lib/mono/gac 的gac 文件夹中加载了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);
        }
    }
}

【问题讨论】:

  • 您是否检查过与 MONO_PATH 变量相同的文件夹?
  • MONO_PATH 变量在哪里?
  • 你是如何安装程序集的?你用过 gacutil 吗?
  • MONO_PATH 是一个环境变量,正如 Jon 所说,您是否使用 gacutil 向 GAC 注册它,将其放在文件夹中并不总是有效。
  • 更新:我在目录上做了一个导出 MONO_PATH,不幸的是我什么也得不到。

标签: c# mysql connector-net idbconnection


【解决方案1】:

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

  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)。谢谢。
  • 对我来说也一样。将mysql.data.dll 重命名为MySql.Data.dll 使单声道运行没有任何问题。
  • 区分大小写对我也有帮助,可笑:p
猜你喜欢
  • 2011-07-24
  • 2011-11-14
  • 1970-01-01
  • 2017-05-23
  • 1970-01-01
  • 2017-12-30
  • 2012-01-04
  • 2019-02-07
  • 1970-01-01
相关资源
最近更新 更多