Hi guys im using VisualStudio2017 to make a chat program from a youtube video
i keep getting an error and wondered if one of you might be able to help me out.

Exception thrown: 'System.InvalidOperationException' in MySql.Data.dll

The code:

Imports System.Security.Cryptography
Imports System.IO
Imports MySql.Data.MySqlClient

Module Con_Add
    Public usernamefriend As String
    Public Conn As New MySqlConnection
    Public ConTemp As New MySqlConnection
    Public MsgSubject As String = String.Empty

    Sub ConTempOpen()
        ConTemp.ConnectionString = "server=localhost" & My.Settings.Host & "; user id=root" & My.Settings.User & "; password=" & My.Settings.Pass & "; database=db_chat " & My.Settings.dbName

        Try
            ConTemp.Open()
        Catch ex As Exception
            MsgBox(ex.Message & vbNewLine & "Check you connection", MsgBoxStyle.Critical, "Can not connect to the database")
            Application.Exit()
        End Try
    End Sub

    Sub OpenConnection()
        Conn.ConnectionString = "server=localhost" & My.Settings.Host & "; user id=root" & My.Settings.User & "; password=" & My.Settings.Pass & "; database=db_chat " & My.Settings.dbName
        Try
            ConTemp.Open()
        Catch ex As Exception
            MsgBox(ex.Message & vbNewLine & "Check you connection", MsgBoxStyle.Critical, "Can not connect to the database")
            Application.Exit()
        End Try
    End Sub


    Function MDSEncrypter(ByVal strPass As String) As String

        Dim Hasher As New MD5CryptoServiceProvider
        Dim PasswordBytes As Byte() = New Byte(strPass.Length + 3) {}
        Dim HashBytes As Byte()

        For i As Integer = 0 To strPass.Length - 1
            PasswordBytes(i) = (CByte(Asc(strPass(i))))

        Next
        PasswordBytes(strPass.Length) = CByte(90)
        PasswordBytes(strPass.Length + 1) = CByte(85)
        PasswordBytes(strPass.Length + 2) = CByte(66)
        PasswordBytes(strPass.Length + 3) = CByte(73)

        HashBytes = Hasher.ComputeHash(PasswordBytes)
        Dim NewHashBytes As Byte() = New Byte(HashBytes.length + 3) {}

        For j As Integer = 0 To HashBytes.length - 1
            NewHashBytes(j) = HashBytes(j)

        Next
        NewHashBytes(HashBytes.Length) = CByte(90)
        NewHashBytes(HashBytes.length + 1) = CByte(85)
        NewHashBytes(HashBytes.length + 2) = CByte(66)
        NewHashBytes(HashBytes.length + 3) = CByte(73)

        strPass = Convert.ToBase64String(NewHashBytes)
        Return strPass
    End Function

    Function ImageToBytes(ByVal imgPath As String) As String
        Try
            Dim Image_DP As Image = Image.FromFile(imgPath)
            Dim memories As MemoryStream = New MemoryStream()

            Image_DP.Save(memories, System.Drawing.Imaging.ImageFormat.Png)

            Dim ImageBytes As Byte() = memories.ToArray()
            Dim StringImage As String = Convert.ToBase64String(ImageBytes)

            Return StringImage

        Catch ex As Exception
            MsgBox(ex.Message & vbNewLine & "Failed to convert image to bytes.", MsgBoxStyle.Exclamation, "Error")
        End Try   
    End Function
End Module

Which line threw the error and when you examine that line, what were the variables you passed in?

no errors on form

I don't expect errors on the form. The error when it happens when you run your app in Visual Studio will stop and well, I have to pause here and ask if you know Visual Studio well enough to run your code there and use its debug capabilities? Your answer to where you are in your training and what tutorial I may look up next.

im only new to it all, been watching videos and copy the codes
in the Output i get

'WindowsApp1.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0b77a5c561934e089\mscorlib.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Phillbert\source\repos\WindowsApp1\WindowsApp1\bin\Debug\WindowsApp1.exe'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0
b03f5f7f11d50a3a\Microsoft.VisualBasic.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0b77a5c561934e089\System.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0
b77a5c561934e089\System.Core.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0b77a5c561934e089\System.Windows.Forms.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0
b03f5f7f11d50a3a\System.Drawing.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0b03f5f7f11d50a3a\System.Configuration.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0
b77a5c561934e089\System.Xml.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Remoting\v4.0_4.0.0.0b77a5c561934e089\System.Runtime.Remoting.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Users\Phillbert\source\repos\WindowsApp1\WindowsApp1\bin\Debug\MySql.Data.dll'. Cannot find or open the PDB file.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0
b77a5c561934e089\System.Data.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0b77a5c561934e089\System.Transactions.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0
b03f5f7f11d50a3a\System.EnterpriseServices.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll'. Symbols loaded.
'WindowsApp1.exe' (CLR v4.0.30319: WindowsApp1.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Management\v4.0_4.0.0.0
b03f5f7f11d50a3a\System.Management.dll'. Symbols loaded.
The thread 0x1cd0 has exited with code 0 (0x0).
Exception thrown: 'System.InvalidOperationException' in MySql.Data.dll
The program '[7380] WindowsApp1.exe' has exited with code 0 (0x0).

There's your clue. "copy the codes"

As the code you supplied so far will never include your MySQL setup I can't verify that your first steps such as the connection string are correct.

You must know your code and single step it in Visual Studio till you find the line that throws the error. Then you can examine that line and what variables are in use at the time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.