C#, System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll

-1

I'm having an error in opening a connection

 public bool Open()
        {
            try
            {
                connection.Open();// in this line I have an error
                return true;
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }

I have these errors:

An unhandled exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll

Additional INFO:

The given key was not present in the dictionary.

OUTPUT:

'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\Users\JB\Desktop\Program\POS\POS\bin\Debug\POS.vshost.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. The thread 0x28b8 has exited with code 259 (0x103). The thread 0x2d2c has exited with code 0 (0x0). The thread 0xc0c has exited with code 259 (0x103). 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\Users\JB\Desktop\Program\POS\POS\bin\Debug\POS.exe'. Symbols loaded. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'. Cannot find or open the PDB file. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\Users\JB\Desktop\Program\POS\POS\bin\Debug\MySql.Data.dll'. Cannot find or open the PDB file. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll'. Cannot find or open the PDB file. 'POS.vshost.exe' (CLR v4.0.30319: POS.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll'. Cannot find or open the PDB file. A first chance exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionPOS.vshost.exeSystem.Collections.Generic.KeyNotFoundException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089The given key was not present in the dictionary. at System.Collections.Generic.Dictionary2.get_Item(TKey key) at MySql.Data.MySqlClient.CharSetMap.GetCharacterSet(DBVersion version, String CharSetName) at MySql.Data.MySqlClient.CharSetMap.GetEncoding(DBVersion version, String CharSetName) at MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection) at MySql.Data.MySqlClient.MySqlConnection.Open() at POS.Class.DBConnect.Open() in c:\Users\JB\Desktop\Program\POS\POS\Class\DBConnect.cs:line 35 at POS.Class.Globals..ctor() in c:\Users\JB\Desktop\Program\POS\POS\Class\Globals.cs:line 26 at POS.Forms.frm_Main..ctor() in c:\Users\JB\Desktop\Program\POS\POS\Forms\frm_Main.cs:line 20 at POS.Program.Main() in c:\Users\JB\Desktop\Program\POS\POS\Program.cs:line 20 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()</StackTrace><ExceptionString>System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.Collections.Generic.Dictionary2.get_Item(TKey key) at MySql.Data.MySqlClient.CharSetMap.GetCharacterSet(DBVersion version, String CharSetName) at MySql.Data.MySqlClient.CharSetMap.GetEncoding(DBVersion version, String CharSetName) at MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection)
at MySql.Data.MySqlClient.MySqlConnection.Open() at POS.Class.DBConnect.Open() in c:\Users\JB\Desktop\Program\POS\POS\Class\DBConnect.cs:line 35 at POS.Class.Globals..ctor() in c:\Users\JB\Desktop\Program\POS\POS\Class\Globals.cs:line 26 at POS.Forms.frm_Main..ctor() in c:\Users\JB\Desktop\Program\POS\POS\Forms\frm_Main.cs:line 20 at POS.Program.Main() in c:\Users\JB\Desktop\Program\POS\POS\Program.cs:line 20 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() The program '[11984] POS.vshost.exe' has exited with code -1 (0xffffffff).

CONNECTION STRING:

Server=127.0.0.1;Initial Catalog=pos;User Id=root;Password=;Allow Zero Datetime=true

c#
asked on Stack Overflow Dec 25, 2020 by Peri Forus • edited Dec 30, 2020 by Peri Forus

1 Answer

0

Obviously, the code is trying to match the key in a dictionary, but the dictionary is empty or the key does not match. Can you provide a little more information about the dictionary? If the error is in that specific line, try F11 key slowly all the way to the external library. This should give you an ide of what the code external code is looking for.

answered on Stack Overflow Dec 25, 2020 by wesreitz • edited Dec 25, 2020 by Dharman

User contributions licensed under CC BY-SA 3.0