Solved

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

Posted on 2013-01-22
4
1,964 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
GridDataView 6 44
Setting runtime form location 4 19
Format column on datatable 7 17
Get list of word ducuments in a folder 10 18
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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 …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

17 Experts available now in Live!

Get 1:1 Help Now