【问题标题】:"Could not load file or assembly" problem with MySQL.Data in .NET core.NET 核心中 MySQL.Data 的“无法加载文件或程序集”问题
【发布时间】:2021-02-12 23:32:21
【问题描述】:

我正在使用 Visual Studio Code 并尝试使用 C# 为 GTA 5 RAGEMP 编写脚本,我对 C# 相当陌生,并且一切顺利,直到我尝试使用来自 oracle 的 MySQL.Data 创建 MySQL 连接器。 在我的尝试中 - 抓住我得到这个:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.'
                String SQLConnection = $"SERVER={sql.Host};PASSWORD={sql.Password};UID={sql.Username};DATABASE={sql.Database}";
                conn = new MySqlConnection(SQLConnection);

                try
                {
                    conn.Open();
                    NAPI.Util.ConsoleOutput("MySQL connection is up!");
                    IsConnectionSetUp = true;

                }
                catch(Exception ex)
                {
                    NAPI.Util.ConsoleOutput(ex.ToString());
                }

我在服务器控制台输出中得到了这个:

Could not load file or assembly 'System.Security.Permissions, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

这在 VSC 控制台输出中:

Exception thrown: 'System.IO.FileNotFoundException' in MySql.Data.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
An exception of type 'System.IO.FileNotFoundException' occurred in System.Private.CoreLib.dll but was not handled in user code
Could not load file or assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

我将 MySQL/Connector 中的所有内容复制到我的运行时文件夹,我尝试使用 NuGet 下载 System.Drawing.Common 和 System.Security.Permissions,我尝试手动将 .DLL 添加到项目依赖项中,但没有任何效果。

【问题讨论】:

    标签: c# mysql .net


    【解决方案1】:

    我猜 RAGEMP 嵌入了一些默认不包含这些程序集的 .NET 运行时版本。

    尝试改用 nuget.org/packages/MySqlConnector。它还支持从 C# 连接到 MySQL,但依赖项更少。

    【讨论】:

      猜你喜欢
      • 2014-11-19
      • 2016-12-22
      • 1970-01-01
      • 2014-01-30
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多