Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql.Data.MySqlClient.Replication.ReplicationManager throws an System.TypeInitializationException

I'm having trouble with my code to access a MySQL Database. Everytime I try to open my connection, a System.TypeInitializationException is thrown by MySql.Data.MySqlClient.Replication.ReplicationManager. Here is my code:

DataTable results = new DataTable("Results");
using (MySqlConnection connection = new MySqlConnection("SERVER=127.0.0.1;DATABASE=foo;UID=bar;PASSWORD=foobar;"))
{
    using (MySqlCommand command = new MySqlCommand(queryString, connection))
    {
        command.Connection.Open(); //throws System.TypeInitializationException
        command.ExecuteNonQuery();

        using (MySqlDataReader reader = command.ExecuteReader())
        results.Load(reader);
    }
}

Edit: I guess MySQL Driver was corrupt. After an upgrade from Windows 7 to Windows 10 everything worked fine.

like image 394
Jan Henry Avatar asked Aug 01 '26 02:08

Jan Henry


2 Answers

I had the same problem but when i installed the MySql.Data.dll using Nuget then the problem is solved Install MySql.Dll file from Nuget,

not from MySQL Website.

like image 110
Mehtab M Avatar answered Aug 03 '26 17:08

Mehtab M


In my case, it raised error only in production. It was due to a wrong assumption in the MySql.Data package. It for some reason seems to demand to be in the same folder as the orchestrating dll (it was referencing another dll which was referencing MySql). I resolved my issue by removing MySql.Data and instead installing MySqlConnector package as suggested in here.

like image 25
Nae Avatar answered Aug 03 '26 19:08

Nae