Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-01-22
4
Medium Priority
?
2,490 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

721 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