We're encountering an error which seems to be related to the WinGrid. On our form we are not creating any background threads or using anything like the background worker. The error ends up crashing the application. This is the stack trace:
Exception:
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.UIElementDrawParams.DrawImageBackground()
at Infragistics.Win.UIElement.DrawImageBackground(UIElementDrawParams& drawParams)
at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams)
at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams)
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.UltraWinGrid.UltraGridUIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode)
at Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe)
at Infragistics.Win.UltraWinGrid.UltraGrid.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)
There are some cells which have background images, but we don't know what's triggering this code. We are wondering if this was a known issue in this version and what, if anything, could we change to prevent it from happening? Unfortunately we are stuck at .Net 3.5 for the time being, so upgrading to a new version isn't an option.
Any help at all with this would be appreciated.
Hello Andy,
After investigating in details your case I believe there are two possible reasons for this exception:
1. You may set too many images as background for your cells. In some moment your application is very close to reaches memory limit for your application and the next image object cannot be created. Then you try use and application throws an exception. You may find more information how to avoid such kind of issues following this link http://help.infragistics.com/Doc/WinForms/current/CLR4.0/?page=WinGrid_Formatting_and_Appearance_based_Performance_Improvement.html
2. On second hand your application may try to reference and image already disposed. This occurs if you create some image, then dispose it and the try to refer it.
Without sample which reproduces this issue those are the only possible reasons which I could make a guesses, if you can send me an example code throwing this exception I will be glad to investigate this in more details for your.
Please check these two possible reasons for the exception and let me know if this solve your issue or if I am missing something.
Thanks for the reply. There's one other detail I forgot to mention, and that is that this issue only appears on Windows 7 Enterprise, we've never had it happen in any other windows edition. Also, the error doesn't happen when first displaying the grid, it happens after we try to update existing rows. I would expect an OutOfMemoryException in your first case, and ObjectDisposedException in the second, however that's not what we're seeing. Since the grid initially displays fine, I don't think its running out of memory.
From the call stack you posted here, the exception is occuring in the property getter for the Width property of an image. So it's not the grid that's blowing up, it's the DotNet Framework. The grid just happens to be accessing the image's Width, but it's the Width property itself that's failing.
The only explanations I can think of are the ones that Mitko already mentioned. The image being disposed seems the most likely explanation. How are you getting the image? Can you post the code you are using to apply the ImageBackground to the grid cell?
In particular, it would be interesting to know if you are loading the image from a stream.