Error I don't understand

PJRoyle

Member
Joined
Jun 7, 2004
Messages
11
Location
Uckfield, East Sussex, UK
Programming Experience
10+
Can anyone help with this?

I have an app running continuously which occasionally gives the following error (the text is from the Exception.StackTrace property):

Item has already been added. Key in dictionary: "-1" Key being added: "-1"

text = at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)

at System.Collections.Hashtable.Add(Object key, Object value)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FRegisterComponent(IMsoComponent component, MSOCRINFOSTRUCT pcrinfo, Int32& dwComponentID)
at System.Windows.Forms.ThreadContext.get_ComponentManager()
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.DoEvents()

(the methods from here on are part of the app)...

at myApp.FrmReadings.makeContact(String strSTD, String strTelNo, String strLogger)
at myApp.FrmReadings.readOneLogger(String strLogger)
at myApp.FrmReadings.readLoop()

All suggestions gratefully received and considered!

Peter Royle
 
You are attempting to add some object to the HashTable collection with a specific key value, but the HashTable collection already contains an object with that key value.

From the looks of it, some line of code is generating a key value of -1 under certain conditions.

Trace back to where you are generating the key values and see if there is some reason you keep getting -1 instead of some unique value.
 
Back
Top