My app adds nodes in 2 ways.
In one case it specifies both a key and text.In the other it specifies text only (null key)
Occasionally [for no obvious reason] the tree is replaced by a large red X and a message box says Item has already been added. Key in dictionary: "Teradata SQL"
This occurs in response to an event - not due to a call from within my code. (It seems to be a Paint event - see trace below)
The problem is that I have searched my entire source base (including resource files) and the only time the string "Teradata SQL" is used it is used for the TEXT property - not the KEY.
Could the Tree somehow get confused if I am adding the nodes within a BeginUpdate/EndUpdate block and specifying a null key?
How can a paint event (which I have no handler for) cause it to attempt to add a node?
Is there any way to trap this error?Maybe add a Paint handler that simply calls your paint handler from inside a catch block ... but I think it is too late by then.
Traceback:
System.ArgumentException: Item has already been added. Key in dictionary: 'Teradata SQL' Key being added: 'Teradata SQL' at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at System.Collections.Hashtable.Add(Object key, Object value) at Infragistics.Win.UltraWinTree.NodeClientAreaUIElement.CacheNodeElements(Hashtable table, UIElementsCollection oldElements, Int32 startIndex) at Infragistics.Win.UltraWinTree.NodeClientAreaUIElement.PositionChildElements() at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements() at Infragistics.Win.UltraWinTree.UltraTreeUIElement.PositionChildElements() at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean clipText, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize, Boolean preventAlphaBlendGraphics) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) at Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe) at Infragistics.Win.UltraWinTree.UltraTree.OnPaint(PaintEventArgs pe) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
ThanksMike
Hello ,
The state of this issue is resolved it should be included in the upcoming Service release.
Thank you for using Infragistics Components.
Hi,
Has this issue been resolved? If so, is there an upgrade available?
I am struggling with the exact same problem.
I have created a support ticket for you with id CAS-84102-752GMV, in order to investigate this issue further for you.
That makes more sense. If it is displaying the 'ToString' value that would probably be the Text.I do add a node with that text to the Tree - but that is also the node where I check for its existance before adding it.
I dont know how there could be 2 UIElements pointing to it since the tree is never referenced from anywhere except the main thread. (The data loaded into this tree comes from small files on the local system so it loads very fast - no need to use threading.)
Hopefully the developers will agree with your assessment as I have now had reports from my Japanese localization team that they are also sometimes hitting the problem.
Thanks
I don't beleive there is any way to catch an exception like this. Once a control blows up during a paint operation, I don't know of any way to recover.
I took another look at the code where the exception is occurring and the caller always creates a new Hashtable before calling the method. So there's no way any nodes could exist in the table at the time the method is called.
The HashTable here is using the node itself as the key, not the Key or Text property of the node. So the message you are getting does not indicate that the problem is with the node's text, it's just showing you the ToString of the node in the error message.
What the code does is loop through the NodeUIElements in the tree and cache them so they can be re-used. So the only way I can see that you could possibly get this error is if you have two NodeUIElements in the tree that are both pointing to the same node. In theory, this should never happen, except in the case of a threading issue.
Having said that... since this is just a caching mechanism for efficiency, I don't see any real harm in us changing this code to avoid the exception. The worst-case scenario would be a slight performance hit, which is certainly preferable to an Exception. So I am going to ask Infragistics Developer Support to write this up and for developer review and we will see if we can get this corrected in the next service release.