Solved

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

Posted on 2013-01-22
4
2,073 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 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