Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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