Hello,
We've encountered a rather strange bug. We have several UltraButtons on a WinForms view.
Application crashes with the following exceptions:
---
System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds. at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable) at Infragistics.Win.AppStyling.StyleInfo.Add(RoleState state, StateInfo stateInfo) at Infragistics.Win.AppStyling.StyleInfo.LoadContents(StyleInfo style, XmlReader reader, StyleParseInfo parseInfo) at Infragistics.Win.AppStyling.StyleInfo.LoadContents(StyleInfo style, StyleParseInfo parseInfo) at Infragistics.Win.AppStyling.StyleInfo.Parse() at Infragistics.Win.AppStyling.StyleInfo.get_StateFlags() at Infragistics.Win.AppStyling.StyleManager.CreateStyleInfo(UIRole role) at Infragistics.Win.AppStyling.UIRole.VerifyCache() at Infragistics.Win.AppStyling.UIRole.ResolveAppearance(AppearanceData& appearance, AppearancePropFlags& requestedProps, RoleState state) at Infragistics.Win.Misc.UltraButtonBase.ResolveAppearanceHelper(UIElementButtonState buttonState, AppearanceData& appearance, AppearancePropFlags& requestedProps, UIRole buttonRole) at Infragistics.Win.Misc.UltraButtonBase.ResolveAppearance(UIElementButtonState buttonState, AppearanceData& appearance, AppearancePropFlags& requestedProps) at Infragistics.Win.Misc.UltraButtonUIElement.InitAppearance(AppearanceData& appearance, AppearancePropFlags& requestedProps) at Infragistics.Win.Misc.UltraButtonUIElement.PositionChildElements() at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) 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 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer) 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)
System.ArgumentException: Parameter is not valid.at System.Drawing.Image.get_Width()at System.Drawing.Image.get_Size()at Infragistics.Win.DrawUtility.DrawImageBackground(Graphics g, AppearanceData& appearanceData, AlphaBlendMode alphaMode, Rectangle invalidRect, Control control, Rectangle relativeRect, ImageAttributes imgAttributes, ColorRenderMode colorRenderMode, Boolean isEnabled)at Infragistics.Win.UIElementDrawParams.DrawImageBackground(AppearanceData& appearance, Rectangle rect, Rectangle invalidRect, Boolean enabled)at Infragistics.Win.Misc.UltraPanelClientAreaUIElement.DrawImageBackground(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.Misc.UltraPanelClientArea.OnPaint(PaintEventArgs e)at System.Windows.Forms.Control.PaintTransparentBackground(PaintEventArgs e, Rectangle rectangle, Region transparentRegion)at System.Windows.Forms.Control.PaintBackground(PaintEventArgs e, Rectangle rectangle, Color backColor, Point scrollOffset)at System.Windows.Forms.Control.PaintBackground(PaintEventArgs e, Rectangle rectangle)at System.Windows.Forms.Control.OnPaintBackground(PaintEventArgs pevent)at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)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)
Any idea why?
Thanks in advance.
So if everything is done in the main UI you should be easy able to isolate this in a small sample which reproduce this and we will be able to investigate. Can you please provide us such sample.
I am waiting for your feedback.
Hello Hristo,
Yes you are right, our application is multithreaded, but the work on the user interface is always done on the main thread.
We are using three different methods to switch the context on the main thread:
- our software is built using SmartClient Software Factory (based on CompositeUI). We are using the event aggregator asking it to switch the call on the UI thread;
- the external calls are made on threads using the ThreadPool and the AsyncOperation. So when the work is done on the child thread, the context is switched back to the main UI thread with asyncOperation.PostOperationCompleted() method;
- on the user control, because of this bug, I am using the BeginInvoke method, again to switch context on the main UI thread.
Even using all these techniques to switch back to the UI thread, we are still getting these errors.
The affected workstations must be faulty in some way.
Thank you.
Hello ,
Based on the call stack of the exception it seems that you are using your UserControl in a multithreading application (Windows Forms controls are not thread safety). It seems to me that you have applied isl from a speared thread (I assume that StyleManager is not in the same thread as the component, or you are doing something with the StyleManager from a separate thread), so when the button is redrawn it cannot copy appearance array the isl. Without sample which demonstrates this issue, those are the only assumptions that I have about what exactly happens here. BeginUpdate()/EndUpdate() might helped here, but it will be better if you put all the code that interact with the component in the main UIThread.
Please let me know if you have any further questions.