You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Core中使用MySQL.Data出现程序集加载失败问题求助

Fixing System.Drawing.Common Load Error with MySQL.Data in RAGE:MP C# Scripts

Hey there! As a fellow RAGE:MP developer who’s been in your shoes, let’s break down how to fix this assembly loading issue you’re facing when trying to connect to MySQL with Oracle’s MySQL.Data library.

Why This Happens

Oracle’s MySQL.Data library has a dependency on System.Drawing.Common in certain versions, and RAGE:MP’s server runtime might not include this assembly by default—especially if your project’s target framework doesn’t match what the server expects. The error you’re seeing means the server can’t locate the exact version of System.Drawing.Common that MySQL.Data is requesting.

Step-by-Step Solutions

Oracle’s MySQL.Data is often bloated and carries unnecessary dependencies like System.Drawing.Common. A far better alternative is MySqlConnector, a lightweight, open-source MySQL client that avoids this exact issue. Here’s how to make the switch:

  • Uninstall the MySQL.Data NuGet package from your project.
  • Install the MySqlConnector NuGet package instead.
  • Update your connection code to use the MySqlConnector implementation:
    using MySqlConnector;
    
    // ...
    
    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());
    }
    

This is the most reliable fix for RAGE:MP environments, as MySqlConnector is widely used in the community and cuts out extra, unneeded dependencies.

2. Match System.Drawing.Common Version to MySQL.Data’s Requirement

If you want to stick with Oracle’s MySQL.Data:

  • Note the exact version of System.Drawing.Common your error mentions (in your case, 4.0.2.0).
  • Install that specific version via NuGet:
    Install-Package System.Drawing.Common -Version 4.0.2.0
    
  • Locate the System.Drawing.Common.dll file from your project’s NuGet packages folder (usually under packages/System.Drawing.Common.4.0.2.0/lib/net4xx/—pick the folder matching your project’s target framework).
  • Copy this DLL into your RAGE:MP server’s server-files directory, or directly into the folder where your compiled script DLL is stored.

3. Align Your Project’s Target Framework with RAGE:MP’s Runtime

RAGE:MP servers typically run on .NET Framework 4.7.2 (double-check your server’s docs to confirm). If your project is targeting .NET Core/.NET 5+, this can cause assembly mismatches:

  • In Visual Studio Code, open your project’s .csproj file.
  • Set the TargetFramework to match the server’s runtime, for example:
    <TargetFramework>net472</TargetFramework>
    
  • Recompile your script and redeploy it to the server.

4. Fix Missing Dependencies Like System.Security.Permissions

Your server console mentioned missing System.Security.Permissions too—here’s how to fix that:

  • Install the System.Security.Permissions NuGet package that matches your target framework.
  • Copy the corresponding DLL from the NuGet packages folder into your server’s runtime directory, just like you did with System.Drawing.Common.

Final Notes

Always clean and rebuild your project after making NuGet or framework changes, and double-check that all required DLLs are present in the server directory where your script runs.

内容的提问来源于stack exchange,提问作者Kopra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 17:52:50