[HELP] [FXServer] MySql.Data.dll official connector throwing IndexOutOfRangeException

I have been trying to get the official Oracle MySql connector to work in C# in FiveM’s new FXServer for a while.

It loads fine, but errors out on the simplest example possible; see below. The connection string is 100% a valid connection string, and works without any issues outside of FXServer in a standalone project.

The source is included, but for convenience, here is the source I use in the example:

using CitizenFX.Core;
using MySql.Data.MySqlClient;

namespace MySqlOfficialConnectorError
{
    public class Main : BaseScript
    {
        public Main()
        {
            try
            { 
                MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection("server=127.0.0.1;uid=yourdbuser;pwd=yourpasswordhere;database=yourrpdb");
                conn.Open();
            }
            catch(MySql.Data.MySqlClient.MySqlException ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
    }
}

The error message it yields is:

Loaded System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a into ScriptDomain_1268010620
Loaded MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d into ScriptDomain_1268010620
Loaded MySqlOfficialConnectorError, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null into ScriptDomain_1268010620
Failed to instantiate instance of script MySqlOfficialConnectorError.Main: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
  at System.Diagnostics.TraceInternal.get_AppName () [0x0000e] in <7d13762c3f3046279fc4d30c52f6f595>:0
  at System.Diagnostics.TraceInternal.TraceEvent (System.Diagnostics.TraceEventType eventType, System.Int32 id, System.String format, System.Object[] args) [0x0003d] in <7d13762c3f3046279fc4d30c52f6f595>:0
  at System.Diagnostics.Trace.TraceError (System.String message) [0x00000] in <7d13762c3f3046279fc4d30c52f6f595>:0
  at MySql.Data.MySqlClient.MySqlTrace.LogError (System.Int32 id, System.String msg) [0x00028] in <2f43badcd692497499db5f314be79b24>:0
  at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver () [0x00031] in <2f43badcd692497499db5f314be79b24>:0
  at MySql.Data.MySqlClient.MySqlPool.GetConnection () [0x0001c] in <2f43badcd692497499db5f314be79b24>:0
  at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00135] in <2f43badcd692497499db5f314be79b24>:0
  at MySqlOfficialConnectorError.Main..ctor () [0x00010] in <06bb8c012456482c8eab36253aaa5edb>:0
  at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
   --- End of inner exception stack trace ---
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00014] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
  at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x000a8] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
  at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
  at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00027] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
  at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00020] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
  at System.Activator.CreateInstance (System.Type type) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0
  at CitizenFX.Core.InternalManager.CreateAssemblyInternal (System.Byte[] assemblyData, System.Byte[] symbolData) [0x00053] in <008df89e273548edb4a43c48cb9c2e12>:0
Started resource mysqldataerror

Here is the resource with all dependencies as well as the source:

And a virus check:
https://www.virustotal.com/file/dac897eccac26b3e965013b45a12fb7f12b0b03a62203138541beae29fc19fa0/analysis/1499112036/

You can either use the assemblies I built/included or download the official connector (MySql.Data.dll) from Oracle and copy the assemblies from your other .NET runtime assemblies. You might have to right click the dlls, go into properties and mark them as safe at the bottom (often happens with downloaded dlls.)

There are other MySql connectors that work rather well, but they do lack some of the features I like with the official connector.

I managed to patch a newer version of a dll that had another error happening, and now that version works.

I can’t vouch for how robust the patch is, but if people are interested I can definitely share it. (At a different computer right now, so can’t share it from here.)

I had reports I was not the only one with the above error, by the way; everybody seems to be having issues.

I just switched to FXServer for C# on the server-side and couldn’t get the MySQL connector to work yet.
Would be awesome, if you can share your solution!

I have the same error :confused: . No one know how to connect?

have you tried using this one instead of the official ?

https://github.com/mysql-net/MySqlConnector

this one is working perfectly wihout touching it