MySQL connection error, cTrader bot built with .Net 6.0

Created at 19 Feb 2023, 15:40
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CT

ctid1830215

Joined 18.02.2023

MySQL connection error, cTrader bot built with .Net 6.0
19 Feb 2023, 15:40


I have a cBOT that connects to a MySQL database.

I use the NuGet package "MySql.Data.MySqlClient"  for database connectivity. Also use the NuGet package "cTrader.Automate". I am using Visual Studio 2022.

I am getting the following error, when the BOT tries to connect to MySQL database.

"The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception".

The MySQL database connectivity worked fine, prior to cBOT migration of .NET 6.0, where I used Visual Studio 2019.

The main question is does cTrader supports MySQL connection in .Net 6.0?. I know it worked with .Net 4.x

Any help to resolve the issue  is much appreciated. 

 

Stack trace below

 

Method => System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlConfiguration' threw an exception.
 ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
   at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
   at System.Configuration.ClientConfigurationHost.get_ConfigPaths()
   at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath)
   at System.Configuration.ClientConfigurationHost.get_IsAppConfigHttp()
   at System.Configuration.Internal.DelegatingConfigHost.get_IsAppConfigHttp()
   at System.Configuration.ClientConfigurationSystem..ctor()
   at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
   at System.Configuration.ConfigurationManager.PrepareConfigSystem()
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at MySql.Data.MySqlClient.MySqlConfiguration..cctor()
   --- End of inner exception stack trace ---
   at MySql.Data.MySqlClient.MySqlConfiguration.get_Settings()
   at MySql.Data.MySqlClient.Replication.ReplicationManager..cctor()


@ctid1830215
Replies

ctid1830215
22 Feb 2023, 22:56

RE:

Hi Support team,

Any update if cTrader (.Net6.0) supports MySQL connectivity. Please provide an yes or no answer. 

If the answer is Yes, please update what changes are needed in code from .Net 4.x to .Net 6.0 code migration. 

 

Thank you and really I appreciate a response.

 

 


@ctid1830215

Spotware
23 Feb 2023, 08:06

Dear trader,

All .NET 6.0 libraries are supported. Unfortunately we do not have a guide for this specific case. 

Best regards,

cTrader Team


@Spotware

stuart
28 Feb 2023, 06:38

RE:

Spotware said:

Dear trader,

All .NET 6.0 libraries are supported. Unfortunately we do not have a guide for this specific case. 

Best regards,

cTrader Team

Hi,

bump

Any chance you can see why this library will not work with .NET 6.0?

I have bots that I have to run as .NET 4.0  

Is it a Threading issue?

do we need to do something with the Connection?

 

 


@stuart

Spotware
28 Feb 2023, 08:19

Dear trader,

Unfortunately we cannot help you with this question, since our teams do not work with the specific technology. A suggestion would be to ask the question in a MySQL community, in case they are familiar with the relevant exception.

Best regards,

cTrader Team


@Spotware

ctid1830215
07 Jun 2023, 22:23

RE:

Just wanted to provide an update on the issue.

To resolve the problem I faced, I replaced the Nuget packge from Oracle "MySql.Data.MySqlClient""  with "MySqlConnector"

Link : NuGet Gallery | MySqlConnector 2.2.6

So, any developer who has a problem connecting to MySql database with .Net 6.0 in cBot, try using "MySqlConnector" Nuget package. Just delete Oracle package and replace with "MySqlConnector". No code changes needed.

I have no idea what's wrong with Oracle package and .Net 6.0, it used to work with .Net 4.x.

Best regards

 

 


@ctid1830215

... Deleted by UFO ...

ctid1830215
11 Aug 2023, 14:59

RE: RE: RE:Hello, how exactly did you set up the connection? Can you show the part of the code?

 

//Install Nuget package  MySqlConnector

 

using MySqlConnector;

 

 

 MySqlConnectionStringBuilder _mySqlConnectionString = new MySqlConnectionStringBuilder();
               _mySqlConnectionString.Server = ParmMySqlHost;
               _mySqlConnectionString.UserID = ParmMySqlUser;
               _mySqlConnectionString.Password = ParmMySqlPassword;
               _mySqlConnectionString.Database = ParmMySqlDatabase;
               _mySqlConnectionString.Port = 3306; // this is hardcoded because "uint" type is not supported by cTrader


       MySqlDBConnection = new MySqlConnection(MySqlConnectionString);
                   MySqlDBConnection.Open();

 

 

Hello, how exactly did you set up the connection? Can you show the part of the code?
THX

 

 

ctid1830215 said: 

Just wanted to provide an update on the issue.

To resolve the problem I faced, I replaced the Nuget packge from Oracle "MySql.Data.MySqlClient""  with "MySqlConnector"

Link : NuGet Gallery | MySqlConnector 2.2.6

So, any developer who has a problem connecting to MySql database with .Net 6.0 in cBot, try using "MySqlConnector" Nuget package. Just delete Oracle package and replace with "MySqlConnector". No code changes needed.

I have no idea what's wrong with Oracle package and .Net 6.0, it used to work with .Net 4.x.

Best regards

 

 

 

 


@ctid1830215