Hi,
I'm experiencing a very strange error with an Ultracheckeditor that might not be exactly an Infragistics' issue, but I hope someone can help.
I've a project that uses WinForms NetAdvantage_NET_20081_CLR20. Last week I've changed its target .NET framework to 3.5, updated its references to NetAdvantage_WinForms_20091 and began exchanging inbox controls for Infragistics' ones. Then on one of my forms a newly added UltracheckEditor (for old CheckBox) started to crash whenever I click it with the mouse or with the space bar (that is positioning on it with the TAB and hit space). If I set its state to checked from the code it works fine, the "tick" is drawn properly, but when the user clicks on it it crashes.
I've tried to reproduce it on a separate project but without success so far.
I'm attaching a screen shot of the error
The first part is setting the check from an event handler (when check 3 is clicked). The second is clicking it with the mouse. The ultracheckeditors are only the "check images", that is they are very small 16;16 and the text next to them is from a label. Also the error happens only on the checkbox 4, the first 3 work fine (they are also newly added). I've tried to delete the erroneous control and add a new one, tried to copy paste from one the working checkeditors, but the same error continues to happen. Tried to reinstall Infragistics WinForm but nothing helped. I've also tried to add a new ultracheckeditor to a new form in the same assembly but without success. Adding ultracheckeditor to other forms in the project also has the same problem. So at some point something broke and I can't add UltraCheckEditors to any form. I've also opened my older project, targetting WinForms NetAdvantage_NET_20081_CLR20 (where I'm using Checkboxes instead of UltraCheckEditor) and tried to add an UltraCheckEditor (from 8.1), but again the error happens. This is so strange, I already have UltraCheckeditors in other forms in the same assembly and they are working fine. Also as I said I was able to substitute 3 of my CheckBoxes to UltraCheckEditors and they are also working, but then suddenly if I try to add ultracheckeditor it is not working. (Reverting project settings won't help since I've already tried it with the older project which uses 8.1 and actually some of the newly added 9.1 UltraCheckEditors are working in the new project).
I'm also pasting a stack trace:
Object reference not set to an instance of an object.Stack Trace: at Infragistics.Win.CheckBoxUIElement.get_TextArea() at Infragistics.Win.EmbeddableCheckUIElement.DrawFocus(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) 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.UltraWinEditors.UltraCheckEditor.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)
Are you using multiple threads in your application? From the call stack it seems that you might be, which could explain the inability to reproduce the issue in a separate application. If this is the case, you need to ensure that any code that could affect the UI (directly or indirectly) is invoked back to the main UI thread, since no UI-based controls are thread-safe in .NET.
-Matt
I'm using threads, but this is not thread related. I'm sure because it happens 100% for every click on the CheckEditor. Also these checkboxes are not updated from a non-ui thread. And clicking on the 3 checkboxes on the left works fine, while equivalent click on the right one leads to the crash. Maybe after I've added the first three to the form something happened and as a result no more checkeditors are "added correctly" or they are, but are not working...
Some of the things I've tried are: reinstalling .net 3.5 sp1, deinstall winforms 8.1, reinstall winforms 9.1. Still the problem remains.
Thanks to you, infragistic team and google. I have the same problem in 8.3 only on one computer (installed our application). The problem was, that the resource file of the dialog has a wrong version number and so the text is set to null (by default a empty text is set when create a new Control).
Thanks a lot!
That was really the problem. The text was being set to null, and string.empty fixed that.
Thank you once again.
I just took a look into the source code to see what might be causing this. Do you happen to be setting the Text of the UltraCheckEditor to null? If I do this, I also happen to get a NullReferenceException in the same location, though not with the same call stack; something about your call stack seems to indicate that the rendering is occurring due to something that happened on another thread, though I can't really say what. If this happens to be the case, try setting the text to String.Empty instead of null and that should solve your problem. Regardless, the fact that the UltraCheckEditor is blowing up is a bug and should be addressed, so I've forwarded this thread to Developer Support so what I've described can be written up accordingly.
I really can't see how the framework or NetAdvantage installations could be the cause of your problem, but the exception is occuring due to the TextUIElement not being initialized. As far as I can tell, this only happens when the Text is null.