I've created an application that queries our internal DB.
This was all working as intended, until I was trying to utilise Microsoft's Trace Source
for logging.
For this I needed to create an Application Configuration File (having not used this before). I ended up not needing the logging so I deleted the .config
file.
After removing this file and doing a little more work, I ran the program and I was suddenly getting a The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.
Error.
Adding the config file back fixed the issue, but there was nothing in the .config
file before or after that seems to relate to the MySQL connection. It legitimately now just contains:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>
Why was removing this file breaking my MySQL connection?
CodePudding user response:
The ReplicationManager
static constructor accesses MySqlConfiguration
which tries to read a configuration section.
There must be a bug in that code that fails when configuration can't be found. If you wanted, you could report it at http://bugs.mysql.com.
Since you said you didn't previously have an application configuration file, I'm assuming you're using .NET 6.0 (or .NET Core 3.1), not .NET Framework (as even a simple .NET Framework application has a configuration file with startup
/supportedRuntime
). Probably something else in your code or app settings changed to support that file, which ended up triggering this bug?
If you are using .NET 6.0, then I'd strongly recommend switching to MySqlConnector (disclaimer: lead author), as it has actual support for async I/O, supports new .NET 6.0 features, and has no dependencies on legacy classes like ConfigurationManager
.