1

Disclosure, I am relatively new to VB.net but not programming in general.

Problem: I created a program that uses a MySql connector to connect to a database. Everything worked great. Yesterday I decided to use My.Settings variables to store some login information. As soon as I did this, My database connections throw this error....

'An exception of type 'System.TypeInitializationException' occurred in MySql.Data.dll but was not handled in user code'

I thought, I must have done something wrong, so I rolled back to my working program, tested it and it still worked. I proceeded to add My.Settings variables again (no code changes), then did a test run, and sure enough the error message came back.

Does anyone have a clue as to why this happens? Any thoughts are most appreciated.

Relevant Information on my system.

  • MySql.Data.dll V8.0.28.0
  • Visual Studio 2022 V17.1.0
  • Language is Visual Basic

Adding Code per nbk's request

Imports MySql.Data.MySqlClient

Public Class Form1

Dim MySQLconn As MySqlConnection

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    MySQLconn = New MySqlConnection()
    MySQLconn.ConnectionString = "server=127.0.0.1;userid=Joe;password=abc123"

    'Test connection
    Try
        MySQLconn.Open()
        MsgBox("Connection to Database Suceeded")
    Catch ex As Exception
        MsgBox("Failed to Connect to Database" + ex.Message)
        Debug.Print(ex.Message)
    Finally
        MySQLconn.Dispose()
    End Try

End Sub

End Class

This above works fine until I add a My.Settings variable. No changes to above code. When I run it after adding code, I begin to get the error.

Full error message below...

System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.

---> System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlConfiguration' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section system.diagnostics. (G:\WORK_IN_PROGRESS\VisualStudio2022_Programs\ExampleProject\bin\Debug\net6.0-windows\ExampleProject.dll.config line 8) at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors() at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey) --- End of inner exception stack trace --- at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey) at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName) at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName) 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() --- End of inner exception stack trace --- at MySql.Data.MySqlClient.Replication.ReplicationManager.IsReplicationGroup(String groupName) at MySql.Data.MySqlClient.MySqlConnection.Open() at ExampleProject.Form1.Button1_Click(Object sender, EventArgs e) in G:\WORK_IN_PROGRESS\VisualStudio2022_Programs\ExampleProject\Form1.vb:line 14

My.Settings Variable I Added

waslost1
  • 11
  • 3
  • can you please provide the code that causes the error and add the complete error text – nbk Feb 24 '22 at 16:21
  • Not sure what to post. As I said, simply adding My.Settings variables breaks the connector. Prior to adding the variables, everything worked fine. Is there something particular you would like to see? – waslost1 Feb 24 '22 at 16:31
  • Added the code snippet. I tried creating a new project and created a My.Settings variable before doing anything else, then I added the connector and the code above. Same results. It seems that the connector cannot be uses if My.Settings is used. – waslost1 Feb 24 '22 at 17:29
  • you missed the part with the variables, so that we can see what is wrong – nbk Feb 24 '22 at 17:44
  • @nbk I added the full error message (I think). Hope that is what you were looking for. I am at a total loss as to why adding a My.Setting variable would break everything so badly. – waslost1 Feb 24 '22 at 17:48
  • @nbk I added a screenshot of the My.Variable part. I don't see any other way to share that. – waslost1 Feb 24 '22 at 17:54
  • i created a new project and got the same error after delete app.config,. everything works fine – nbk Feb 24 '22 at 18:31
  • I am seeing exactly the same thing. Now I wonder if deleting that file will break other things later on LOL. So far so good, thanks a ton. – waslost1 Feb 24 '22 at 20:10

0 Answers0