Solved

'The given key was not present in the dictionary' - Why this error happend???

Posted on 2013-01-22
4
2,030 Views
Last Modified: 2013-01-23
A few moments ago visual basic .net send me this error: 'The given key was not present in the dictionary'

The problem was in this function:
    Private Delegate Sub delegate_crea_dispositivos(ByVal titulo As String, ByVal titulo1 As String, ByVal indice As String, ByVal indice1 As Integer)
    Private Sub crea_dispositivos(ByVal titulo As String, ByVal titulo1 As String, ByVal indice As String, ByVal indice1 As Integer)
        If Me.InvokeRequired Then
            Me.Invoke(New delegate_crea_dispositivos(AddressOf crea_dispositivos), titulo, titulo1, indice, indice1)

        Else
            paso_medio_graficas(titulo, titulo1, indice, indice1)
            FillData_dispositivos(indice, indice1)
        End If
    End Sub

Open in new window


when the program came to this line:  If Me.InvokeRequired Then fire up the error

The details of the exception was:
No se controló System.Collections.Generic.KeyNotFoundException
  Message="La clave proporcionada no se encontró en el diccionario."
  Source="System.Windows.Forms"
  StackTrace:
       en System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
       en System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
       en _2bocas.grafica_p6.crea_dispositivos(String titulo, String titulo1, String indice, Int32 indice1) en D:\PROYECTOS\PROGRAMACION\PROYECTO 2BOCAS\2bocasfisicas\ddlabv6\version3\2bocas\grafica_p6.vb:línea 190
       en _2bocas.grafica_p6.tuberia_crudo() en D:\PROYECTOS\PROGRAMACION\PROYECTO 2BOCAS\2bocasfisicas\ddlabv6\version3\2bocas\grafica_p6.vb:línea 142
       en System.Threading.ExecutionContext.runTryCode(Object userData)
       en System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       en System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

Open in new window


unfortunately I dont save the error message and I cannot reproduce it again

I fix this problem by deleting the code of the function and write it again

But just for my knowledge why that error happend I why I fix the problem write it again the function
0
Comment
Question by:altariamx2003
  • 2
  • 2
4 Comments
 

Author Comment

by:altariamx2003
ID: 38806112
It happend again

this is the error message
error
0
 
LVL 23

Accepted Solution

by:
apresto earned 500 total points
ID: 38806166
The reason an error like this occurs is if you are trying to access an entry in a collection which doesnt exist. For example, lets say you have an array/collection with the following entries:

MyArray[0] = Peter
MyArray[1] = John
MyArray[2] = Paul

And you try to reference MyArray[3], you will get a similar error because you are referencing an entry which doesnt exist. The reason you are getting "The given key doesnt exist" is because you must be trying to reference a collection of Key/Value pairs. But the same principle applies. This normally occurs in a loop. It's more difficult to debug in a multithreaded application.

Try setting break points before the error occurs and stepping through your code.

Does this explanation as to why the error occurs make sense?
0
 

Author Comment

by:altariamx2003
ID: 38806271
Yes

It make sense

And I found that the problem was an Array inside "FillData_dispositivos"

Thanks a lot for your help!!!!
0
 
LVL 23

Expert Comment

by:apresto
ID: 38809448
No problem, I'm glad I could help

apresto
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now